I change the row height of a tree view from within a delegate's sizeHint method. It is within sizeHint that I get the value from a spinbox in a toolbar, and set the row height to the value in the spinbox. To make sure the size hint is actually called, I aim to refresh the view when the spinbox value is changed.
My question is this: in such cases of purely cosmetic changes, what is the recommended way to tell the view to refresh? Is there some method built specifically for such cases? Obviously, this question assumes my general strategy for adjusting row height is sound, which I am also open to correction on. There are a few methods for telling the view that it is time to refetch the data and redraw things: layoutChanged, reset, setModel, dataChanged. Hell, I found that even just calling expandAll on the tree was enough to update my view to show the new row height.
In practice, I found using layoutChanged works extremely well:
QtGui.QStandardItemModel.layoutChanged.emit()
To copy to clipboard, switch view to plain text mode
It is sort of uncommon usage, as that is more for when you have rearranged your data (e.g., by sorting).
I also tried following the more commonly suggested practice of emitting dataChanged:
QtGui.QStandardItemModel.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
To copy to clipboard, switch view to plain text mode
This does not work. Even if it did, it would also be something of a hack, because it is telling the view that the data has changed in the model. When it hasn't. Interestingly, I found that while layoutChanged does call sizeHint, calling dataChanged only calls paint, but not sizeHint. So the suggestion here:
http://www.qtcentre.org/threads/4823...fresh-the-view
Doesn't work for purely cosmetic changes like changing row height, it seems.
Perhaps I'm missing a better technique, but layoutChanged() seems to work well in my standard item model. I'm wondering if I'm missing an obvious better way.
----------------------
Note I posed this question at Stack Overflow:
http://stackoverflow.com/questions/3...qt-pyside-pyqt
Bookmarks