diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2024-04-10 17:10:15 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-04-14 14:40:41 +0000 |
commit | 892576b7499a221b4b46e2421442dd577813d36a (patch) | |
tree | 81e9d4be615d0da1da355e4378e900fd7bf123e6 | |
parent | 269a6cb2d574a31d53371c1991de42e7a6cf5582 (diff) |
Fix Text with ElideRight rendering when margins are set
Commit 127c79fb7fda16b9a48ce8c425d1700d1aa7502d already addressed the
issue, but didn't take into account the fact that the old width can be
negative when the non-zero margins are set.
Provide a trivial fix and extend the unit-tests.
Amends 127c79fb7fda16b9a48ce8c425d1700d1aa7502d.
Fixes: QTBUG-83408
Fixes: QTBUG-33608
Pick-to: 6.5 6.2
Change-Id: I7c43bd72f63d577995138ad4aa3e1195011b6bc9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit 235bbe8c644415a83e3f5103eff7c4ef4181164a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick/items/qquicktext.cpp | 4 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/data/elideZeroWidthWithMargins.qml | 27 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 12 |
3 files changed, 41 insertions, 2 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 6dfc323be1..74562761c1 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -2662,8 +2662,10 @@ void QQuickText::geometryChange(const QRectF &newGeometry, const QRectF &oldGeom } } } else if (!heightChanged && widthMaximum) { - if (!qFuzzyIsNull(oldGeometry.width())) { + if (oldGeometry.width() > 0) { // no change to height, width is adequate and wasn't 0 before + // (old width could also be negative if it was 0 and the margins + // were set) goto geomChangeDone; } } diff --git a/tests/auto/quick/qquicktext/data/elideZeroWidthWithMargins.qml b/tests/auto/quick/qquicktext/data/elideZeroWidthWithMargins.qml new file mode 100644 index 0000000000..bb269e6ad5 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/elideZeroWidthWithMargins.qml @@ -0,0 +1,27 @@ +import QtQuick + +Item { + id: root + property bool ok: false + width: 640 + height: 480 + + Text { + id: text + text: "This is a quite long text. Click me and i should remain visible!!! Sadly this doesn't happen" + elide: Text.ElideRight + anchors { + fill: parent + margins: 1 + } + } + + Component.onCompleted: { + text.width = 300; + text.height = 0; + text.width = 0; + text.height = 30; + text.width = 300; + root.ok = text.paintedWidth > 0 && text.paintedHeight > 0 + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 6bd99e6741..b731f1b069 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -53,6 +53,7 @@ private slots: void wrap(); void elide(); void elideParentChanged(); + void elideRelayoutAfterZeroWidth_data(); void elideRelayoutAfterZeroWidth(); void multilineElide_data(); void multilineElide(); @@ -589,10 +590,19 @@ void tst_qquicktext::elideParentChanged() QCOMPARE(actualItemImageGrab, expectedItemImageGrab); } +void tst_qquicktext::elideRelayoutAfterZeroWidth_data() +{ + QTest::addColumn<QByteArray>("fileName"); + + QTest::newRow("no_margins") << QByteArray("elideZeroWidth.qml"); + QTest::newRow("with_margins") << QByteArray("elideZeroWidthWithMargins.qml"); +} + void tst_qquicktext::elideRelayoutAfterZeroWidth() { + QFETCH(const QByteArray, fileName); QQmlEngine engine; - QQmlComponent component(&engine, testFileUrl("elideZeroWidth.qml")); + QQmlComponent component(&engine, testFileUrl(fileName.constData())); QScopedPointer<QObject> root(component.create()); QVERIFY2(root, qPrintable(component.errorString())); QVERIFY(root->property("ok").toBool()); |