aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-05-02 17:22:46 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2022-05-09 19:20:06 +0200
commitea898f614dcded4012d45a254b044dc7b37c40c0 (patch)
treee18b3494ea990cdfb3926c2c84e5b8e0fbe6232d /tests
parent0121c6737c7374d6b21eee4eeed861da2ef77999 (diff)
Text: don't fall back to full-width layout if availableWidth == 0
If Text.width == Text.rightPadding, there is no space to render any text; but in that case, QQuickTextPrivate::availableWidth() returns 0: it's incorrect to fall back to layout.maximumWidth() and allow rendering the whole line. Prior to 6ec2693d4a3c95ca9ff0c349d3c587a7f1402c05 we were checking width() here, so let's do that again. Fixes: QTBUG-83413 Change-Id: I3ee3b49406577c3aa005a3ca3606308ff0a21d8d Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit 406ff6b53d02b8db4231e473982fe593fb1e48c6) Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktext/data/padding.qml26
-rw-r--r--tests/auto/quick/qquicktext/data/paddingInLoader.qml14
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp45
3 files changed, 85 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktext/data/padding.qml b/tests/auto/quick/qquicktext/data/padding.qml
index ab0a37d041..f830af0e40 100644
--- a/tests/auto/quick/qquicktext/data/padding.qml
+++ b/tests/auto/quick/qquicktext/data/padding.qml
@@ -9,4 +9,30 @@ Text {
leftPadding: 30
rightPadding: 40
bottomPadding: 50
+
+ Rectangle {
+ width: parent.leftPadding
+ height: parent.height
+ color: "#6600FF00"
+ }
+
+ Rectangle {
+ width: parent.width
+ height: parent.topPadding
+ color: "#66888800"
+ }
+
+ Rectangle {
+ x: parent.width - parent.rightPadding
+ width: parent.rightPadding
+ height: parent.height
+ color: "#6600FFFF"
+ }
+
+ Rectangle {
+ y: parent.height - parent.bottomPadding
+ width: parent.width
+ height: parent.bottomPadding
+ color: "#66880088"
+ }
}
diff --git a/tests/auto/quick/qquicktext/data/paddingInLoader.qml b/tests/auto/quick/qquicktext/data/paddingInLoader.qml
new file mode 100644
index 0000000000..6ef7c25a9b
--- /dev/null
+++ b/tests/auto/quick/qquicktext/data/paddingInLoader.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.12
+
+Item {
+ width: 30
+ height: 30
+ Loader {
+ anchors.fill: parent
+ sourceComponent: Text {
+ rightPadding: 30
+ text: "Some text"
+ elide: Text.ElideRight
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index fe3f696dfa..ff191bbc7f 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE
extern void qt_setQtEnableTestFont(bool value);
QT_END_NAMESPACE
+Q_LOGGING_CATEGORY(lcTests, "qt.quick.tests")
+
class tst_qquicktext : public QQmlDataTest
{
Q_OBJECT
@@ -153,6 +155,7 @@ private slots:
void growFromZeroWidth();
void padding();
+ void paddingInLoader();
void hintingPreference();
@@ -4342,6 +4345,20 @@ void tst_qquicktext::padding()
obj->setElideMode(QQuickText::ElideRight);
QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding());
+
+ obj->setLeftPadding(0);
+ QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
+
+ obj->setWidth(cw);
+ obj->setRightPadding(cw);
+ QCOMPARE(obj->contentWidth(), 0);
+
+ for (int incr = 1; incr < 50 && qFuzzyIsNull(obj->contentWidth()); ++incr)
+ obj->setWidth(cw + incr);
+ QVERIFY(obj->contentWidth() > 0);
+ qCDebug(lcTests) << "increasing Text width from" << cw << "to" << obj->width()
+ << "rendered a character: contentWidth now" << obj->contentWidth();
+
obj->setElideMode(QQuickText::ElideNone);
obj->resetWidth();
@@ -4386,6 +4403,34 @@ void tst_qquicktext::padding()
delete root;
}
+void tst_qquicktext::paddingInLoader() // QTBUG-83413
+{
+ QQuickView view(testFileUrl("paddingInLoader.qml"));
+ view.show();
+ view.requestActivate();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QQuickText *qtext = view.rootObject()->findChild<QQuickText*>();
+ QVERIFY(qtext);
+ QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(qtext);
+ QVERIFY(textPrivate);
+ QCOMPARE(qtext->contentWidth(), 0); // does not render text, because width == rightPadding
+ QCOMPARE(textPrivate->availableWidth(), 0);
+
+ qtext->setLeftPadding(qtext->width());
+ qtext->setRightPadding(0);
+ QCOMPARE(qtext->contentWidth(), 0); // does not render text, because width == leftPadding
+ QCOMPARE(textPrivate->availableWidth(), 0);
+
+ qtext->setRightPadding(qtext->width());
+ QCOMPARE(qtext->contentWidth(), 0); // does not render text: available space is negative
+ QCOMPARE(textPrivate->availableWidth(), -qtext->width());
+
+ qtext->setLeftPadding(2);
+ qtext->setRightPadding(2);
+ QVERIFY(qtext->contentWidth() > 0); // finally space is available to render text
+ QCOMPARE(textPrivate->availableWidth(), qtext->width() - 4);
+}
+
void tst_qquicktext::hintingPreference()
{
{