[Qt-interest] Using Qt delegate to render list of icons with tooltips?

Sean Harmer sean.harmer at maps-technology.com
Mon Oct 26 15:58:47 CET 2009


Hi,

On Monday 26 Oct 2009 14:49:30 Thomi Richards wrote:
> Sorry I should have been more explicit.
> 
> 2009/10/26 Sean Harmer <sean.harmer at maps-technology.com>:
> > Is each icon in it's own cell? ie Is there a one to one mapping between
> > icons and QModelIndex's?
> 
> Nope - I have one cell, and in that cell I want a horizontal list of icons.

Ah OK.

> > If you have several icons and tool tips for any particular QModelIndex
> > then you will need to provide a custom delegate.
> 
> Right - but I can't see how the tooltips will work - I can use a
> custom delegate to render the pixmaps just fine, but i can't see how
> to get a different tooltip for each icon.

How are you drawing your delegate? Is it using child widgets such as a QLabel 
for each icon or are you simply using QPainter functions directly?

If you are using child widgets, just get your model to return the tooltip 
texts as a QVariantList and assign each element to the respective child 
widget's tooltip property.

If you are using QPainter directly, then you can use the above technique for 
getting the list of tool tip strings, but instead of setting them on the child 
widgets you need to show a different text depending upon where the cursor is 
hovered.

Looking at the documentation for QToolTip you will see this:

"It is also possible to show different tool tips for different regions of a 
widget, by using a QHelpEvent of type QEvent::ToolTip. Intercept the help 
event in your widget's event() function and call QToolTip::showText() with the 
text you want to display. The Tooltips example illustrates this technique."

That should be all that you need I think.

HTH,

Sean



More information about the Qt-interest-old mailing list