diff options
author | Yulong Bai <yulong.bai@qt.io> | 2018-01-22 14:36:17 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-02-06 19:35:37 +0000 |
commit | 63899f3185b443ba3cdb7f34cf09f0ac01c5c037 (patch) | |
tree | 03db570fe92b4eecfa1aa825b255804e48faa3f1 /src/quicktemplates2/qquicktooltip.cpp | |
parent | 72abc4e94764b4a5592a9d153ff9991fe66d7395 (diff) |
QQuickToolTip: add non-attached show() and hide() methods
Usually there's only one global ToolTip instance providing attached
show() and hide() methods, here we add non-attached ones which would be
more flexible to meet different needs.
[ChangeLog][ToolTip] Added non-attached show() and hide() methods to
make it more flexible to meet certain requirements.
Task-number: QTBUG-62890
Change-Id: I432bca202e16a27d0a5a732445242e78b2fb9c3f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicktooltip.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktooltip.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index 1bf6ca55..f5c88d2e 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -276,6 +276,31 @@ QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object) return new QQuickToolTipAttached(object); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlmethod void QtQuick.Controls::ToolTip::show(string text, int timeout = -1) + + This method shows the tooltip with \a text and \a timeout (milliseconds). +*/ +void QQuickToolTip::show(const QString &text, int ms) +{ + if (ms >= 0) + setTimeout(ms); + setText(text); + open(); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlmethod void QtQuick.Controls::ToolTip::hide() + + This method hides the tooltip. +*/ +void QQuickToolTip::hide() +{ + close(); +} + QFont QQuickToolTip::defaultFont() const { return QQuickControlPrivate::themeFont(QPlatformTheme::TipLabelFont); @@ -520,10 +545,8 @@ void QQuickToolTipAttached::show(const QString &text, int ms) tip->resetWidth(); tip->resetHeight(); tip->setParentItem(qobject_cast<QQuickItem *>(parent())); - tip->setTimeout(ms >= 0 ? ms : d->timeout); tip->setDelay(d->delay); - tip->setText(text); - tip->open(); + tip->show(text, ms >= 0 ? ms : d->timeout); } /*! |