Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.15.2, 6.2.4, 6.3.1
-
None
-
-
013c346a8d (qt/qtbase/dev) 013c346a8d (qt/tqtc-qtbase/dev) 70e33a585c (qt/qtbase/6.4) 70e33a585c (qt/tqtc-qtbase/6.4) 07bde1cadf (qt/tqtc-qtbase/6.2) 991c056438 (qt/tqtc-qtbase/dev)
Description
Found this while investigating QTBUG-89557.
QTextLayout::maximumWidth() doesn't take into account line separator for multi-line text.
Reproduced on the current Dev as well.
Code sample:
#include <QGuiApplication> #include <QTextLayout> qreal layoutMaximumWidth(const QString &text) { QTextLayout layout(text); layout.beginLayout(); while (layout.createLine().isValid()) { } layout.endLayout(); return layout.maximumWidth(); } int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); qreal w1 = layoutMaximumWidth("test"); qDebug() << "singleline maxwidth:" << w1; qreal w2 = layoutMaximumWidth("test\ntest"); qDebug() << "multiline maxwidth:" << w2; Q_ASSERT(qFuzzyCompare(w1, w2)); return 0; }
Output:
singleline maxwidth: 19.4688
multiline maxwidth: 38.9375
ASSERT: "qFuzzyCompare(w1, w2)" in file ..\textLayout\main.cpp, line 24
For the test case above w1 should be equal to w2, and the ASSERT should not fire.
See full example textLayout.zip
Attachments
Issue Links
- relates to
-
QTBUG-95853 QTextLayout detecting new line in text
-
- Reported
-
-
QTBUG-106909 QML Text's implicit size is not correct for an item with fixed size
-
- Closed
-
-
QTBUG-89557 QML Text's implicitWidth is wrong when wrapMode is set for multiline text.
-
- Closed
-
-
QTBUG-106947 QTextLayout::maximumWidth() doesn't handle spaces correctly
-
- Closed
-
For Gerrit Dashboard: QTBUG-104986 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
433371,10 | QTextLayout: fix maximumWidth() for a text containing line separator | dev | qt/qtbase | Status: MERGED | +2 | 0 |
433832,2 | QTextLayout: fix maximumWidth() for a text containing line separator | 6.4 | qt/qtbase | Status: MERGED | +2 | 0 |
433835,2 | QTextLayout: fix maximumWidth() for a text containing line separator | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |
434531,2 | Revert "QTextLayout: fix maximumWidth() for a text containing line separator" | dev | qt/qtbase | Status: MERGED | +2 | 0 |
434719,2 | Revert "QTextLayout: fix maximumWidth() for a text containing line separator" | 6.4 | qt/qtbase | Status: MERGED | +2 | 0 |
434725,2 | Revert "QTextLayout: fix maximumWidth() for a text containing line separator" | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |
435080,6 | QTextLayout: fix maximumWidth() for a text containing line separator | dev | qt/qtbase | Status: MERGED | +2 | 0 |