PDA

View Full Version : Problems customizing tooltips in QListView



kalos80
12th November 2007, 13:59
I have a problem customizing tooltips for QListView.

I had to add a custom tooltip object to my list view in order to show some information when the cursor is over some columns in the list view.

For the other columns I want the default behavior, I mean show the tooltip with the cell text if the text is truncated.

The problem is that the new tooltip object override the default one. I tried to use in the maybetip function of my custom tooltip the code of the tooltip in the QListView class, but it accesses some private fields of the QListViewItem in order to determine whether the text is truncated.

I tried also to use the following code to determine whether the text is truncated



...
if( view->header()->sectionSize( colIndex ) < item->width( view->fontMetrics(), view, colIndex ) )
tip( rect, item->text(colIndex) );
...


it is working for all the columns except for the first one, because it does not take into account the box size of the QCheckListItem, the decorator size (+ or -) and the depth of the item.

Thanks in advance for your suggestions!

DeepDiver
12th November 2007, 14:07
Are you using the Model-View-Concept (http://doc.trolltech.com/4.3/model-view-programming.html)?
In this case you have full control over the tooltip.
In you implementaion of the model method data() you can return your tooltip-string for the displayrole Qt::ToolTipRole.

You can even have different tooltips on each cell.

Good luck - let us know if you need more info.

kalos80
12th November 2007, 14:28
I think you are talking about Qt 4... Unfortunately I'm working with Qt3 :crying:

DeepDiver
12th November 2007, 14:35
Ooops .... :o

I'm sorry - didn't look close enough ....

You need to upgrade than :p (<--- joke!!!)

wysota
12th November 2007, 18:34
Did you try using QListView::columnWidth(int) to fetch the column width and QListView::itemAt() to determine which item is under cursor?

kalos80
13th November 2007, 14:44
Did you try using QListView::columnWidth(int) to fetch the column width and QListView::itemAt() to determine which item is under cursor?


view->header()->sectionSize( colIndex )

is a similar way to find the size of the column.
The problem is that other than the size of the column I need to know the width needed by the item to be drawn in such column.

The width needed by the cell in the first column of an item is determined by:
The Text size (known)
The Pixmap size (known)
The size of the decorator of the QCheckListItem (unknown)
The size of the box of the QCheckListItem (unknown)
The indentation of the QChecklist item (if the item is child of other items the first column is indented) (unknown)

I do not know how to compute the size of the unknown elements

wysota
14th November 2007, 22:46
I do not know how to compute the size of the unknown elements

The elements are drawn according to the style. You can query the active style for the size. It's possible that you can query for the complete size you need. Just take a look at what QStyle offers.