Results 1 to 4 of 4

Thread: How to determine the header row height in QTreeView

  1. #1
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question How to determine the header row height in QTreeView

    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
    Qt Code:
    1. QTreeView::headerData(0, Qt::Horizontal, Qt::SizeHintRole)
    To copy to clipboard, switch view to plain text mode 
    only returns a QSize(-1,-1) which probably corresponds to a QVariant().

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to determine the header row height in QTreeView

    Either ask for its height() or better yet ask the view for the index underneath the pointer using QAbstractItemView::indexAt.

  3. #3
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: How to determine the header row height in QTreeView

    Quote Originally Posted by wysota View Post
    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.
    Andreas

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to determine the header row height in QTreeView

    Probably you should have done this:

    Qt Code:
    1. QModelIndex index = view->indexAt(view->viewport()->mapFromGlobal(QCursor::pos()));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to wysota for this useful post:

    ghorwin (20th September 2007)

Similar Threads

  1. QTreeView and QDirModel Header Sort Question
    By jimroos in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 08:04
  2. qt4+xp: QTreeView w/o header ?
    By incapacitant in forum Newbie
    Replies: 1
    Last Post: 5th March 2006, 18:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.