aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquicktooltip.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquicktooltip.cpp')
-rw-r--r--src/quicktemplates2/qquicktooltip.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp
index ddf434a2..8b61375e 100644
--- a/src/quicktemplates2/qquicktooltip.cpp
+++ b/src/quicktemplates2/qquicktooltip.cpp
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
/*!
\qmltype ToolTip
\inherits Popup
- \instantiates QQuickToolTip
+//! \instantiates QQuickToolTip
\inqmlmodule QtQuick.Controls
\since 5.7
\ingroup qtquickcontrols2-popups
@@ -188,7 +188,7 @@ void QQuickToolTip::setText(const QString &text)
return;
d->text = text;
- setAccessibleName(text);
+ maybeSetAccessibleName(text);
emit textChanged();
}
@@ -238,12 +238,13 @@ void QQuickToolTip::setTimeout(int timeout)
if (d->timeout == timeout)
return;
+ d->timeout = timeout;
+
if (timeout <= 0)
d->stopTimeout();
else if (isVisible())
d->startTimeout();
- d->timeout = timeout;
emit timeoutChanged();
}
@@ -251,9 +252,18 @@ void QQuickToolTip::setVisible(bool visible)
{
Q_D(QQuickToolTip);
if (visible) {
- if (!d->visible && d->delay > 0) {
- d->startDelay();
- return;
+ if (!d->visible) {
+ // We are being made visible, and we weren't before.
+ if (d->delay > 0) {
+ d->startDelay();
+ return;
+ }
+ } else {
+ // We are being made visible, even though we already were.
+ // We've probably been re-opened before our exit transition could finish.
+ // In that case, we need to manually start the timeout, as that is usually
+ // done in itemChange(), which won't be called in this situation.
+ d->startTimeout();
}
} else {
d->stopDelay();
@@ -272,9 +282,10 @@ QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object)
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
- \qmlmethod void QtQuick.Controls::ToolTip::show(string text, int timeout = -1)
+ \qmlmethod void QtQuick.Controls::ToolTip::show(string text, int timeout)
- This method shows the tooltip with \a text and \a timeout (milliseconds).
+ This method shows the \a text as a tooltip, which times out in
+ \a timeout (milliseconds).
*/
void QQuickToolTip::show(const QString &text, int ms)
{
@@ -327,10 +338,14 @@ void QQuickToolTip::timerEvent(QTimerEvent *event)
if (event->timerId() == d->timeoutTimer.timerId()) {
d->stopTimeout();
QQuickPopup::setVisible(false);
- } else if (event->timerId() == d->delayTimer.timerId()) {
+ return;
+ }
+ if (event->timerId() == d->delayTimer.timerId()) {
d->stopDelay();
QQuickPopup::setVisible(true);
+ return;
}
+ QQuickPopup::timerEvent(event);
}
#if QT_CONFIG(accessibility)
@@ -345,7 +360,7 @@ void QQuickToolTip::accessibilityActiveChanged(bool active)
QQuickPopup::accessibilityActiveChanged(active);
if (active)
- setAccessibleName(d->text);
+ maybeSetAccessibleName(d->text);
}
#endif
@@ -551,8 +566,9 @@ void QQuickToolTipAttached::hide()
QQuickToolTip *tip = d->instance(false);
if (!tip)
return;
-
- tip->close();
+ // check the parent item to prevent unexpectedly closing tooltip by new created invisible tooltip
+ if (parent() == tip->parentItem())
+ tip->close();
}
QT_END_NAMESPACE