Results 1 to 3 of 3

Thread: Access QTreeWidgetItem from a QTreeWidget's item delegate

  1. #1
    Join Date
    Apr 2009
    Posts
    12

    Default Access QTreeWidgetItem from a QTreeWidget's item delegate

    I have a QTreeWidget object on a form and I'm using an item delegate to allow me to override how the columns are displayed.

    I want my second column to be a progress bar so in the item delegate's paint() method I override the option passed in with a new QStyleOptionProgressBar (as is the method used in the torrent example).

    This all works well but from inside that paint() method I want to be able to access the relevant QTreeWidgetItem that it is painting and I can't figure out how to do it.

    There are three objects passed in: a QPainter, a QStyleOptionViewItem and a QModelIndex.

    In the torrent example it does something similar by using the row from the QModelIndex but I can't do that as I have rows within rows so there can be many instances of row 1, for example. Plus, it seems like a bit of a hack anyway.

    There must be a way to do this but I've been reading the docs and looking at examples for a couple of hours and I can't figure it out.

    Please help.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Access QTreeWidgetItem from a QTreeWidget's item delegate

    row is relative to parent. And QTreeWidgetItem is provided for use instead of QModelIndex (QTreeWidget and Items are based on Model/View so they use QTreeView and QModelIndexes as well but you don't see it). But every QTreeWidgetItem has it corresponding QModelIndex containing the same data, and having the same row, column and parent (but QModelIndex parent). I don't really know what exactly you want to get from the item but i think that for example current progress shuold be store in the item and if you want to paint it just use index.data(YourRoleStoringProgress) and thats it.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Apr 2009
    Posts
    12

    Default Re: Access QTreeWidgetItem from a QTreeWidget's item delegate

    That's exactly what I wanted, cheers. I'm now storing the progress in role 32 and it's working a treat.

Similar Threads

  1. Replies: 5
    Last Post: 10th August 2009, 11:50
  2. Delegate for a certain item?
    By somebody in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2008, 23:55
  3. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 08:37
  4. Access from Delegate to Model
    By starcontrol in forum Qt Programming
    Replies: 5
    Last Post: 11th April 2008, 13:26
  5. QTreeWidget's Item Widgets
    By jpn in forum Qt Programming
    Replies: 11
    Last Post: 2nd April 2006, 00:56

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.