4

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.

Andreas Haferburg
  • 5,189
  • 3
  • 37
  • 63

2 Answers2

6

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);
    }
}
jonspaceharper
  • 4,207
  • 2
  • 22
  • 42
1

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.

Andreas Haferburg
  • 5,189
  • 3
  • 37
  • 63
  • 1
    Wow, yet another reason why Qt is a terrible UI framework. This is unforgivably sloppy. It doesn't even respect platform settings when it is eminently possible to do so. Accessibility requires the ability for a user to change tooltip timeouts, and it's something that should be configured at a system level, not per-application. If I do that on Windows, Qt applications happily ignore it, making my life more difficult. – Cody Gray - on strike Jun 01 '16 at 05:08
  • 1
    @CodyGray Don't hate on them. :) UI frameworks are incredibly complex. In the 4.8 code there's actually a comment saying that they planned customization for Qt 5. Maybe they didn't get around to it earlier, or it never came up. And yes, I agree, the default should come from a system-wide setting. – Andreas Haferburg Jun 01 '16 at 09:27
  • I realize they are complex. I've written a few. Nowhere near as comprehensive as Qt, of course, because they haven't been for public consumption. But to be on version 4 of a public-facing framework, used by lots of different vendors, and still not respect platform settings is inexcusable. I have a general policy of not considering the use of applications not written using a native UI. Things like this are the reason why. "Cross-platform" is seductive-sounding, until you realize it means your app is fundamentally broken on *all* platforms. Oops. – Cody Gray - on strike Jun 07 '16 at 09:25
  • @CodyGray i.e. Java, broken everywhere. But Qt is fun, you can always hack around everything. In this case, you can implement a custom tooltip mechanism. – user1095108 Mar 06 '20 at 14:52