diff options
author | Wang Chuan <ouchuanm@outlook.com> | 2019-08-23 22:28:56 +0800 |
---|---|---|
committer | ouchuan <ouchuanm@outlook.com> | 2019-08-29 07:25:45 +0800 |
commit | 35acc9fc3c41446bacbbfe754f7f494de7f62411 (patch) | |
tree | 48104fb6fb867f635db35e855ea60b5cbe3bcdc0 | |
parent | 8577f12bf4dfd9adfe8c5b85a3712bf1cc5ba0c3 (diff) |
QQuickTextNodeEngine: don't create background when its alpha is 0
If the alpha value for the background color of a text element is 0,
we don't need to create a rectangle node to represent it, as the
rectangle will be invisible anyway.
[ChangeLog][QtQuick][QQuickTextNodeEngine] don't create a new
rectangle node as the background of text, when the alpha of it is
0
Fixes: QTBUG-76137
Change-Id: I40c624ee8f61740fd07e7d3751a78b6224882913
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r-- | src/quick/items/qquicktextnodeengine.cpp | 4 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/data/transparentBackground.qml | 16 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 22 |
3 files changed, 40 insertions, 2 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index 5a4ef2b686..f407de84cb 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -781,8 +781,8 @@ void QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode, for (int i = 0; i < m_backgrounds.size(); ++i) { const QRectF &rect = m_backgrounds.at(i).first; const QColor &color = m_backgrounds.at(i).second; - - parentNode->addRectangleNode(rect, color); + if (color.alpha() != 0) + parentNode->addRectangleNode(rect, color); } // Add all text with unselected color first diff --git a/tests/auto/quick/qquicktext/data/transparentBackground.qml b/tests/auto/quick/qquicktext/data/transparentBackground.qml new file mode 100644 index 0000000000..a10a1779bb --- /dev/null +++ b/tests/auto/quick/qquicktext/data/transparentBackground.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Rectangle { + width: 200 + height: 200 + color: "white" + Text { + objectName: "text" + textFormat: Text.RichText + anchors.fill: parent + color: "black" + text: "<h1 style=\"background-color:rgba(255,255,255,0.00)\">foo</h1>" + verticalAlignment: Text.AlignTop + horizontalAlignment: Text.AlignLeft + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index eafa6cb052..3414bec4a6 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -163,6 +163,8 @@ private slots: void verticallyAlignedImageInTable(); + void transparentBackground(); + private: QStringList standard; QStringList richText; @@ -4428,6 +4430,26 @@ void tst_qquicktext::verticallyAlignedImageInTable() // Don't crash } +void tst_qquicktext::transparentBackground() +{ + if ((QGuiApplication::platformName() == QLatin1String("offscreen")) + || (QGuiApplication::platformName() == QLatin1String("minimal"))) + QSKIP("Skipping due to grabToImage not functional on offscreen/minimimal platforms"); + + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("transparentBackground.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QImage img = window->grabWindow(); + QCOMPARE(img.isNull(), false); + + QColor color = img.pixelColor(0, 0); + QCOMPARE(color.red(), 255); + QCOMPARE(color.blue(), 255); + QCOMPARE(color.green(), 255); +} QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" |