From c1fd9b4439928ca6e1918f34e8f1c3c9c1cacf59 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Fri, 24 Jul 2020 20:20:13 +0200 Subject: [PATCH] Add timeout property to ToolTipArea --- src/declarativeimports/core/tooltip.cpp | 7 +++++++ src/declarativeimports/core/tooltip.h | 9 +++++++++ src/declarativeimports/core/tooltipdialog.cpp | 15 +++++++++++++-- src/declarativeimports/core/tooltipdialog.h | 3 +++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/declarativeimports/core/tooltip.cpp b/src/declarativeimports/core/tooltip.cpp index 3a9ce7f87..edf26e797 100644 --- a/src/declarativeimports/core/tooltip.cpp +++ b/src/declarativeimports/core/tooltip.cpp @@ -41,6 +41,7 @@ ToolTip::ToolTip(QQuickItem *parent) m_textFormat(Qt::AutoText), m_active(true), m_interactive(false), + m_timeout(4000), m_usingDialog(false) { setAcceptHoverEvents(true); @@ -158,6 +159,7 @@ void ToolTip::showToolTip() mainItem()->setVisible(true); } + dlg->setHideTimeout(m_timeout); dlg->setOwner(this); dlg->setLocation(location); dlg->setVisualParent(this); @@ -257,6 +259,11 @@ void ToolTip::setInteractive(bool interactive) emit interactiveChanged(); } +void ToolTip::setTimeout(int timeout) +{ + m_timeout = timeout; +} + void ToolTip::hideToolTip() { m_showTimer->stop(); diff --git a/src/declarativeimports/core/tooltip.h b/src/declarativeimports/core/tooltip.h index 94f17c779..dd96e0ad1 100644 --- a/src/declarativeimports/core/tooltip.h +++ b/src/declarativeimports/core/tooltip.h @@ -124,6 +124,12 @@ class ToolTip : public QQuickItem */ Q_PROPERTY(bool interactive MEMBER m_interactive WRITE setInteractive NOTIFY interactiveChanged) + /** + * Timeout in milliseconds after which the tooltip will hide itself. + * Set this value to -1 to never hide the tooltip automatically. + */ + Q_PROPERTY(int timeout MEMBER m_timeout WRITE setTimeout) + public: /// @cond INTERNAL_DOCS explicit ToolTip(QQuickItem *parent = nullptr); @@ -156,6 +162,8 @@ public: void setActive(bool active); void setInteractive(bool interactive); + + void setTimeout(int timeout); /// @endcond public Q_SLOTS: @@ -218,6 +226,7 @@ private: bool m_active; bool m_interactive; int m_interval; + int m_timeout; //ToolTipDialog is not a Q_GLOBAL_STATIC because QQuickwindows as global static //are deleted too later after some stuff in the qml runtime has already been deleted, diff --git a/src/declarativeimports/core/tooltipdialog.cpp b/src/declarativeimports/core/tooltipdialog.cpp index 9c092e8c8..5e717b32b 100644 --- a/src/declarativeimports/core/tooltipdialog.cpp +++ b/src/declarativeimports/core/tooltipdialog.cpp @@ -70,8 +70,9 @@ QQuickItem *ToolTipDialog::loadDefaultItem() void ToolTipDialog::showEvent(QShowEvent *event) { - m_showTimer->start(m_hideTimeout); - + if (m_hideTimeout > 0) { + m_showTimer->start(m_hideTimeout); + } Dialog::showEvent(event); } @@ -142,4 +143,14 @@ void ToolTipDialog::valueChanged(const QVariant &value) setPosition(value.toPoint()); } +void ToolTipDialog::setHideTimeout(int timeout) +{ + m_hideTimeout = timeout; +} + +int ToolTipDialog::hideTimeout() const +{ + return m_hideTimeout; +} + #include "moc_tooltipdialog.cpp" diff --git a/src/declarativeimports/core/tooltipdialog.h b/src/declarativeimports/core/tooltipdialog.h index 10fc91ffb..108242be5 100644 --- a/src/declarativeimports/core/tooltipdialog.h +++ b/src/declarativeimports/core/tooltipdialog.h @@ -55,6 +55,9 @@ public: bool interactive(); void setInteractive(bool interactive); + int hideTimeout() const; + void setHideTimeout(int timeout); + /** * Basically the last one who has shown the dialog */