diff options
-rw-r--r-- | src/quicktemplates2/qquicktooltip.cpp | 10 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_tooltip.qml | 25 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index 65e81fda..d47589ba 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -379,8 +379,8 @@ void QQuickToolTipAttached::setText(const QString &text) d->text = text; emit textChanged(); - if (QQuickToolTip *tip = d->instance(true)) - tip->setText(text); + if (isVisible()) + d->instance(true)->setText(text); } /*! @@ -405,6 +405,9 @@ void QQuickToolTipAttached::setDelay(int delay) d->delay = delay; emit delayChanged(); + + if (isVisible()) + d->instance(true)->setDelay(delay); } /*! @@ -429,6 +432,9 @@ void QQuickToolTipAttached::setTimeout(int timeout) d->timeout = timeout; emit timeoutChanged(); + + if (isVisible()) + d->instance(true)->setTimeout(timeout); } /*! diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml index fb9ffdc3..04064fa1 100644 --- a/tests/auto/controls/data/tst_tooltip.qml +++ b/tests/auto/controls/data/tst_tooltip.qml @@ -118,6 +118,11 @@ TestCase { var spy2 = signalSpy.createObject(item2, {target: item2.ToolTip, signalName: data.signalName}) verify(spy2.valid) + var sharedTip = ToolTip.toolTip + var sharedSpy = signalSpy.createObject(testCase, {target: sharedTip, signalName: data.signalName}) + verify(sharedSpy.valid) + + // change attached properties while the shared tooltip is not visible item1.ToolTip[data.property] = data.setValue compare(item1.ToolTip[data.property], data.setValue) compare(spy1.count, 1) @@ -125,6 +130,26 @@ TestCase { compare(spy2.count, 0) compare(item2.ToolTip[data.property], data.defaultValue) + // the shared tooltip is not visible for item1, so the attached + // property change should therefore not apply to the shared instance + compare(sharedSpy.count, 0) + compare(sharedTip[data.property], data.defaultValue) + + // show the shared tooltip for item2 + item2.ToolTip.visible = true + verify(item2.ToolTip.visible) + verify(sharedTip.visible) + + // change attached properties while the shared tooltip is visible + item2.ToolTip[data.property] = data.setValue + compare(item2.ToolTip[data.property], data.setValue) + compare(spy2.count, 1) + + // the shared tooltip is visible for item2, so the attached + // property change should apply to the shared instance + compare(sharedSpy.count, 1) + compare(sharedTip[data.property], data.setValue) + item1.destroy() item2.destroy() } |