PDA

View Full Version : Creating a Tooltip-like widget for mouse-hover of QListView items



TropicalPenguin
19th November 2011, 22:48
Hello.

I have a QListView in which I have arranged the items of an item model in a grid (using the icons from each item's Qt::DecorationRole).

What I would like to do now is to create an effect whereby, when the user hovers the mouse over one of the items in this grid - after a given delay - a box containing information about the hovered item is displayed somewhere near the cursor.

The box can not be constrained by the size of the viewport.

The problem is that I am not very sure where to begin. As far as I understand delegates, they seem insufficient for achieving this. Regular tooltips even more so (since their content's layout is fairly fixed).

Would this be a matter of creating a QWidget-subclass (layed out in whatever way I need) with certain window flags somewhere in my QListView subclass after the firing of a timer after a hover has been detected?

Any ideas?

Thanks in advance.

ChrisW67
21st November 2011, 01:33
Why is Qt::ToolTipRole not suitable?

TropicalPenguin
23rd November 2011, 12:16
I'm sure Qt::ToolTipRole is perfectly suitable.

I was wondering more about the mechanics of how to temporarily display such an 'overlay' above the window containing my view.

d_stranz
26th November 2011, 01:40
You simply return a QString containing the tooltip text. Qt will take care of displaying it.

ChrisW67
26th November 2011, 06:14
You can have some control over the display style of the standard tool tip text using style sheets attached to QToolTip.