View Full Version : Row Height Resizing with QAbstractItemModel & QTreeView

18th August 2011, 19:20
I am interested in seeing if anyone has any problems with resizing row heights in QTreeView.

I'd like to have a view with 4 columns of custom data. One of those columns can vary is content size by a good bit so I have word wrapping on the tree set. As I resize a column I'd like the visible row heights to update accordingly. Basically, I want to have the whole thing do a layout again when a column resize operation is complete.

The behavior I see is that the rows don't resize in height. Items are getting their original size from the model for Qt::Role = SizeHintRole using the data(...) virtual. This works for all items as they are displayed during the original layout. As you scroll or change column widths all i can get to happen is the data(..) with SizeHintRole is only ever called for the first item. This would make sense if I was using uniformRowHeights but I'm not. I actually traced in Qt code and found where they are doing it for row(0) and find this odd.

Best I have been able to do:
I can bind the signal for columnReized from headview to a slot which I can then use to call view->doItemsLayout(). This gives me what I want except that its called too often. Seems like every pixel change which is excessive for a layout. I basically just want this done when the user has completed a column resize.

Does this make sense? Anyone ever been able to make something like this work. I could probably accomplish this with with some very complex delegates PER ROW but that seems overkill and the amount of delegates I would need would diminish the performance gain I get for using models instead of item based widgets.

Any thoughts?