From a063cd0be5e8f108a0084831856f4af8c0e9159c Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 4 May 2021 15:48:28 +0200 Subject: 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 Pick-to: 6.1 5.15 Change-Id: I7ca3805429acb68a13ead8f3545bb84a51fb1b72 Reviewed-by: Fabian Kosmale --- tests/auto/controls/data/tst_tooltip.qml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/controls/data/tst_tooltip.qml') diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml index b4e992a4..2f98a5f3 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 } @@ -446,6 +451,19 @@ TestCase { 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) + } + function test_timeoutAfterOpened() { let control = createTemporaryObject(toolTipWithExitTransition, testCase, { timeout: 1, exit: null }) verify(control) -- cgit v1.2.3