diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2021-05-04 15:48:28 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2021-06-09 15:52:57 +0200 |
commit | 10ede696d063de6bd7d3484bdfc8b83cb2ebdd68 (patch) | |
tree | 6e0d23c67b106341904ee7b4d14f2a3aba1b6951 /tests | |
parent | 104cd475f255a826671e4b624e97dd39e05e3fba (diff) |
ToolTip: use contentWidth of Text contentItem to account for newlines
By default, QQuickPopupItem uses the implicitWidth of its contentItem,
which is too large in the case of a ToolTip with newlines in the text.
In that case, contentWidth refers to the width of the text including
newlines, so we use that instead.
[ChangeLog][Controls][ToolTip] The implicit width of ToolTips now
accounts for newlines in the text. If you want to use the old behavior,
set ToolTip's contentWidth to implicitContentWidth.
Fixes: QTBUG-83630
Change-Id: I7ca3805429acb68a13ead8f3545bb84a51fb1b72
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit a063cd0be5e8f108a0084831856f4af8c0e9159c)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_tooltip.qml | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml index 6d45b09d..154eb2bf 100644 --- a/tests/auto/controls/data/tst_tooltip.qml +++ b/tests/auto/controls/data/tst_tooltip.qml @@ -75,6 +75,11 @@ TestCase { SignalSpy { } } + Component { + id: itemComponent + Item {} + } + QtObject { id: object } @@ -218,8 +223,8 @@ TestCase { } function test_warning() { - ignoreWarning(Qt.resolvedUrl("tst_tooltip.qml") + ":78:5: QML QtObject: ToolTip must be attached to an Item") - ignoreWarning("<Unknown File>:1:30: QML ToolTip: cannot find any window to open popup in.") + ignoreWarning(new RegExp(".*QML QtObject: ToolTip must be attached to an Item")) + ignoreWarning(new RegExp(".*QML ToolTip: cannot find any window to open popup in.")) object.ToolTip.show("") // don't crash (QTBUG-56243) } @@ -474,4 +479,17 @@ TestCase { compare(item.ToolTip.toolTip.contentItem.wrapMode, Text.Wrap) verify(item.ToolTip.toolTip.contentItem.width < item.ToolTip.toolTip.contentItem.implicitWidth) } + + // QTBUG-83630: Test that newlines are accounted for in the implicit contentWidth. + function test_newLines() { + var item = createTemporaryObject(itemComponent, testCase) + verify(item) + + item.ToolTip.show("This is one line of text\nThis is another line of text") + + // The implicitWidth of the Text item for the text above will be larger than + // its contentWidth. ToolTip's implicitWidth uses contentWidth in its calculation, + // so we check that it's less than the Text's implicitWidth. + verify(item.ToolTip.toolTip.implicitWidth < item.ToolTip.toolTip.contentItem.implicitWidth) + } } |