aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYulong Bai <yulong.bai@qt.io>2018-01-22 14:36:17 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2018-02-06 19:35:37 +0000
commit63899f3185b443ba3cdb7f34cf09f0ac01c5c037 (patch)
tree03db570fe92b4eecfa1aa825b255804e48faa3f1
parent72abc4e94764b4a5592a9d153ff9991fe66d7395 (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>
-rw-r--r--src/imports/controls/ToolTip.qml2
-rw-r--r--src/imports/controls/fusion/ToolTip.qml2
-rw-r--r--src/imports/controls/imagine/ToolTip.qml2
-rw-r--r--src/imports/controls/material/ToolTip.qml2
-rw-r--r--src/imports/controls/universal/ToolTip.qml2
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp3
-rw-r--r--src/quicktemplates2/qquicktooltip.cpp29
-rw-r--r--src/quicktemplates2/qquicktooltip_p.h4
-rw-r--r--tests/auto/controls/data/tst_tooltip.qml18
9 files changed, 56 insertions, 8 deletions
diff --git a/src/imports/controls/ToolTip.qml b/src/imports/controls/ToolTip.qml
index 46f7f577..1812cc6d 100644
--- a/src/imports/controls/ToolTip.qml
+++ b/src/imports/controls/ToolTip.qml
@@ -37,7 +37,7 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Controls.impl 2.4
-import QtQuick.Templates 2.4 as T
+import QtQuick.Templates 2.5 as T
T.ToolTip {
id: control
diff --git a/src/imports/controls/fusion/ToolTip.qml b/src/imports/controls/fusion/ToolTip.qml
index 2b404a5e..28bb12dc 100644
--- a/src/imports/controls/fusion/ToolTip.qml
+++ b/src/imports/controls/fusion/ToolTip.qml
@@ -35,7 +35,7 @@
****************************************************************************/
import QtQuick 2.11
-import QtQuick.Templates 2.4 as T
+import QtQuick.Templates 2.5 as T
import QtQuick.Controls 2.4
import QtQuick.Controls.impl 2.4
import QtQuick.Controls.Fusion 2.4
diff --git a/src/imports/controls/imagine/ToolTip.qml b/src/imports/controls/imagine/ToolTip.qml
index 81a5e8aa..39ba83ea 100644
--- a/src/imports/controls/imagine/ToolTip.qml
+++ b/src/imports/controls/imagine/ToolTip.qml
@@ -35,7 +35,7 @@
****************************************************************************/
import QtQuick 2.11
-import QtQuick.Templates 2.4 as T
+import QtQuick.Templates 2.5 as T
import QtQuick.Controls.Imagine 2.4
import QtQuick.Controls.Imagine.impl 2.4
diff --git a/src/imports/controls/material/ToolTip.qml b/src/imports/controls/material/ToolTip.qml
index bb7a9d7c..0d690f59 100644
--- a/src/imports/controls/material/ToolTip.qml
+++ b/src/imports/controls/material/ToolTip.qml
@@ -35,7 +35,7 @@
****************************************************************************/
import QtQuick 2.11
-import QtQuick.Templates 2.4 as T
+import QtQuick.Templates 2.5 as T
import QtQuick.Controls.Material 2.4
T.ToolTip {
diff --git a/src/imports/controls/universal/ToolTip.qml b/src/imports/controls/universal/ToolTip.qml
index 1c7c7b69..b8829bbd 100644
--- a/src/imports/controls/universal/ToolTip.qml
+++ b/src/imports/controls/universal/ToolTip.qml
@@ -35,7 +35,7 @@
****************************************************************************/
import QtQuick 2.11
-import QtQuick.Templates 2.4 as T
+import QtQuick.Templates 2.5 as T
import QtQuick.Controls.Universal 2.4
T.ToolTip {
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index d8df7d98..877c997d 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -325,6 +325,9 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickScrollBar, 4>(uri, 2, 4, "ScrollBar");
qmlRegisterType<QQuickScrollIndicator, 4>(uri, 2, 4, "ScrollIndicator");
qmlRegisterType<QQuickSpinBox, 4>(uri, 2, 4, "SpinBox");
+
+ // QtQuick.Templates 2.5 (new types and revisions in Qt 5.12)
+ qmlRegisterType<QQuickToolTip, 5>(uri, 2, 5, "ToolTip");
}
QT_END_NAMESPACE
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);
}
/*!
diff --git a/src/quicktemplates2/qquicktooltip_p.h b/src/quicktemplates2/qquicktooltip_p.h
index 60b02502..432bdd8e 100644
--- a/src/quicktemplates2/qquicktooltip_p.h
+++ b/src/quicktemplates2/qquicktooltip_p.h
@@ -84,6 +84,10 @@ Q_SIGNALS:
void delayChanged();
void timeoutChanged();
+public Q_SLOTS:
+ Q_REVISION(5) void show(const QString &text, int ms = -1);
+ Q_REVISION(5) void hide();
+
protected:
QFont defaultFont() const override;
QPalette defaultPalette() const override;
diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml
index e7cc6787..99b6ee14 100644
--- a/tests/auto/controls/data/tst_tooltip.qml
+++ b/tests/auto/controls/data/tst_tooltip.qml
@@ -329,4 +329,22 @@ TestCase {
verify(tooltip.visible)
}
}
+
+ Component {
+ id: nonAttachedToolTipComponent
+ ToolTip { }
+ }
+
+ function test_nonAttachedToolTipShowAndHide() {
+ var tip = createTemporaryObject(nonAttachedToolTipComponent, testCase)
+ verify(tip)
+ tip.show("hello");
+ verify(tip.visible)
+ verify(tip.text === "hello")
+ tip.hide()
+ tryCompare(tip, "visible", false)
+ tip.show("delay", 200)
+ verify(tip.visible)
+ tryCompare(tip, "visible", false)
+ }
}