Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query and change the time it takes for a QToolTip to appear?

Tags:

c++

qt

Is it possible to change the time delay between the mouse being still in a window, and the tooltip's show event?

Is there a Qt wrapper for something like TTM_SETDELAYTIME? According to the Windows documentation, the default value depends on the double-click interval.

like image 816
Andreas Haferburg Avatar asked Mar 12 '23 03:03

Andreas Haferburg


2 Answers

You'll have to set a custom QProxyStyle that overrides styleHint() and returns your preferred value for QStyle::SH_ToolTip_WakeUpDelay. Sample code below.

class CustomStyle : public QProxyStyle
{
Q_OBJECT
\\...
public:
    int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
                  const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
    {
        if (hint == SH_ToolTip_WakeUpDelay)
            return someCustomValue;
        else
            return QProxyStyle::styleHint(hint, option, widget, returnData);
    }
}
like image 109
jonspaceharper Avatar answered Mar 14 '23 16:03

jonspaceharper


Apparently that's not possible with the built-in Qt Tooltips. In 4.8 qapplication.cpp they use magic numbers:

d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive()?20:700, this);

So the default behavior is to show a tooltip after 700 ms, and start a 2000 ms fall-asleep timer. If we hover over another window(widget) with the fall-asleep timer still active, the delay will be reduced to 20 ms, probably under the assumption that the first tooltip was not the one the user wanted.

like image 39
Andreas Haferburg Avatar answered Mar 14 '23 16:03

Andreas Haferburg