PDA

View Full Version : Tooltips which follow the mouse



Alundra
11th October 2015, 20:12
Hi,
Is it possible to have the tooltips which follow the mouse ?
The question is about tooltips of QMenu and QTreeWidgetItem but if a generic method works for all it's better.
How achieve that if it's possible ?
Thanks

d_stranz
12th October 2015, 19:39
QToolTip is just a QWidget. You can create one and show() or hide() it any time and anywhere you want. They are normally used in connection with some other widget, to give a hint about what a particular GUI item or command does.

So if you display one somewhere off in space, not in association with anything but just following the mouse around, how is that going to help the user?

Alundra
12th October 2015, 20:49
It's just to change it to be dynamic and not static when the cursor is on a menu for example.
The only way is to inherit QMenu and manage to show a QTooltip manually ?

d_stranz
12th October 2015, 21:43
The default behavior is to show the tooltip after a slight delay if the mouse is not moving, and to hide it after a certain period of time or if the mouse moves. In Qt 5.2+ you can set the tool tip duration, but it will still hide if the mouse moves.

If you don't like this behavior, then you do not have to inherit QMenu. You can install an event filter on your menu instance and respond to the QEvent types Enter, Leave, MouseMove, and MouseButtonPress. For Enter, you should start a single-shot QTimer and wait until it fires, then show your own QToolTip. For Leave, you hide the tool tip if it is visible. For MouseMove, you need to move the tool tip. For MouseButtonPress you need to hide it as well. In any case, you need to disable the menu's normal tool tip handling.

Seems like a lot of work for something which will quickly become very annoying to users. What if you used an application like this, and there was no way for you to get the *%&# tool tip to go away? It's stuck to the mouse, no matter how hard you shake it. In every other application you use, moving the mouse makes it go away, but not this one. Time to file a bug report.

Alundra
12th October 2015, 22:38
The default behavior is to show the tooltip after a slight delay if the mouse is not moving, and to hide it after a certain period of time or if the mouse moves. In Qt 5.2+ you can set the tool tip duration, but it will still hide if the mouse moves.
I don't have this behavior using Qt 5.5.0, after a delay the tooltip is shown, doesn't move and is not hidden until the mouse is out of the widget.
If the qtooltip follows the cursor it end to the same behavior but the tooltip moves.