PDA

View Full Version : Tooltips & Qt4 tree views



yogeshm02
15th January 2006, 14:43
Hi

I've looked everywhere in the documentation but not found any hint about setting tooltips for QTreeView in an intelliigent way (like Qt3's QListView i.e. tooltips are displayed when item are not shown at once).

How can i do that in Qt4?

Thanks in advance

wysota
15th January 2006, 15:41
Make your model return the tooltip text of each of the items for the Qt::ToolTipRole role.

yogeshm02
16th January 2006, 15:46
Make your model return the tooltip text of each of the items for the Qt::ToolTipRole role.
I know that. But then the tooltips are always shown not when the contents are not shown entirely.

Am i clear?

wysota
16th January 2006, 18:29
I don't quite understand. Can you provide an example or somewhat broader explanation?

If I understand, you want to show the tooltip only if a column is too narrow for the whole text of the item to fit in it?

wysota
16th January 2006, 18:34
If you want to change the way the view displays the tooltip, you'll have to handle QAbstractItemView::viewportEvent().

yogeshm02
17th January 2006, 14:44
If I understand, you want to show the tooltip only if a column is too narrow for the whole text of the item to fit in it?
Yes. This is what i want and Qt3's QListView does that by default.

If you want to change the way the view displays the tooltip, you'll have to handle QAbstractItemView::viewportEvent().
I think this should be the default behaviour. What do you say?

Thanks for your patience

wysota
17th January 2006, 15:44
I think this should be the default behaviour. What do you say?

No, this shouldn't be a default behaviour. Why? If an item has a tooltip, it is the tooltip that is displayed and not the item name. It sounds very sane to me.

yogeshm02
17th January 2006, 16:12
No, this shouldn't be a default behaviour. Why? If an item has a tooltip, it is the tooltip that is displayed and not the item name. It sounds very sane to me.
Agreed with above. But i wanted that behaviour if no tooltip was specified. I'll inherit from QTreeView and see if i can do what i want and if i am successful then i will post here. Bye till then.

Thanks