PDA

View Full Version : How to determine the header row height in QTreeView



ghorwin
20th September 2007, 12:34
Hi there,

in a class derived from QTreeView I need to find out he height of the header row in order to correct the coordinates reported in a hover event and find the model index corresponding to the mouse position. It turns out, that the position reported is relative to the top left corner of the widget, but I need the coordinate relative to the top left corner of the inner tree view itself. Thus, I need to find out the height of the header row.

However, calling the parent's class function

QTreeView::headerData(0, Qt::Horizontal, Qt::SizeHintRole)
only returns a QSize(-1,-1) which probably corresponds to a QVariant().

So, how can I find out the height of the header row?

wysota
20th September 2007, 12:48
Either ask for its height() or better yet ask the view for the index underneath the pointer using QAbstractItemView::indexAt.

ghorwin
20th September 2007, 18:25
Either ask for its height() or better yet ask the view for the index underneath the pointer using QAbstractItemView::indexAt.

Well, I already use QAbstractItemView::indexAt but it gives me the model index one or two below the one my mouse hovers above (because the position that indexAt requests must be relative to the top left corner of the white tree view area).

However, I finally managed to get it using treeView->header()->sizeHint(), so I guess this is the way to go about it.

wysota
20th September 2007, 19:39
Probably you should have done this:


QModelIndex index = view->indexAt(view->viewport()->mapFromGlobal(QCursor::pos()));