PDA

View Full Version : Adjusting height of QTreeWidgetItems depending on level in QTreeWidget



rensdenobel
21st November 2008, 16:28
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 ?



QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const
{
if(index.parent().isValid())
{
return QSize(284,20);
}
else
{
return QSize(284,50);
}
}

rensdenobel
21st November 2008, 17:06
Fixed it already, my bad. I had "uniformrowheights" property of QTreeWidget checked :confused: Sorry for the confusion. It works like a charm now.