Add timeout property to ToolTipArea

This commit is contained in:
Alexander Lohnau 2020-07-24 20:20:13 +02:00
parent 3caaaae585
commit c1fd9b4439
4 changed files with 32 additions and 2 deletions

View File

@ -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();

View File

@ -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,

View File

@ -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"

View File

@ -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
*/