chatterino2
chatterino2 copied to clipboard
Links sometimes don't wrap enough
Describe the bug Sometimes very long links appear onto other monitors for me, it should wrap more
To reproduce
- Hover over a long link
Screenshots
Chatterino version Chatterino Nightly 2.2.3-beta2 (commit 529f19a2d, 17.11.2020)
Operating system Windows 10
The screenshot link is dead. Was this about tooltips from links being too long and wrapping onto your second monitor?
The screenshot link is dead. Was this about tooltips from links being too long and wrapping onto your second monitor?
I believe it was for links like this
Others have had similar issues (https://github.com/freedomofpress/securedrop-client/issues/815). We can't set a max-width on the label due to QTBUG-85498, and we can't use a QTextEdit
in read-only mode as we need to shrink the widget to its contents (not that easy with a QTextEdit
).
I found that setting the word wrap here to QTextOption::WrapAtWordBoundaryOrAnywhere
solves the issue for us. I'll see if that's a decent fix for Qt.
Edit: We need a bit more as we need to handle both HTML-like text and raw text
Diff
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 70bcd92fdd..43049c32dd 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -7243,8 +7243,12 @@ start_lengthVariant:
else
engine.option.setAlignment(Qt::AlignLeft); // do not do alignment twice
- if (!option && (tf & Qt::TextWrapAnywhere))
- engine.option.setWrapMode(QTextOption::WrapAnywhere);
+ if (!option && (tf & Qt::TextWrapAnywhere)) {
+ if (tf & Qt::TextWordWrap)
+ engine.option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
+ else
+ engine.option.setWrapMode(QTextOption::WrapAnywhere);
+ }
if (tf & Qt::TextJustificationForced)
engine.forceJustification = true;
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp
index bc40b0f442..f9b18f40ca 100644
--- a/src/widgets/widgets/qlabel.cpp
+++ b/src/widgets/widgets/qlabel.cpp
@@ -473,9 +473,9 @@ void QLabel::setWordWrap(bool on)
{
Q_D(QLabel);
if (on)
- d->align |= Qt::TextWordWrap;
+ d->align |= Qt::TextWordWrap | Qt::TextWrapAnywhere;
else
- d->align &= ~Qt::TextWordWrap;
+ d->align &= ~(Qt::TextWordWrap | Qt::TextWrapAnywhere);
d->updateLabel();
}
@@ -1551,7 +1551,7 @@ void QLabelPrivate::ensureTextLayouted() const
opt.setAlignment(QFlag(this->align));
if (this->align & Qt::TextWordWrap)
- opt.setWrapMode(QTextOption::WordWrap);
+ opt.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
else
opt.setWrapMode(QTextOption::ManualWrap);
This is probably too much for Qt, as this changes the meaning of specifying both TextWordWrap
and TextWrapAnywhere
at the same time.