Results 1 to 2 of 2

Thread: Adjusting height of QTreeWidgetItems depending on level in QTreeWidget

  1. #1

    Default Adjusting height of QTreeWidgetItems depending on level in QTreeWidget

    Hello,

    I'm constructing a QTreeWidget for which the height of the items has to differ depending on the level. E.g. for the first level, the height has to be 20px, for the second level, 20 px, but for the third level, the height has to be 50px.

    I use a QItemDelegate to draw the items in the QTreeWidget and tried to override the sizeHint property as in the following code snippet. Note that the logic isn't correct.

    But, it's about the index.parent().isValid() part. It seems like the sizeHint does not do anything with that. When debugging I always end up in the else statement.

    What am I doing wrong and is there an alternative that I should be working on instead of trying to modify the sizeHint ?


    Qt Code:
    1. QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const
    2. {
    3. if(index.parent().isValid())
    4. {
    5. return QSize(284,20);
    6. }
    7. else
    8. {
    9. return QSize(284,50);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2

    Default Re: Adjusting height of QTreeWidgetItems depending on level in QTreeWidget

    Fixed it already, my bad. I had "uniformrowheights" property of QTreeWidget checked Sorry for the confusion. It works like a charm now.

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.