Qt 5.0.2/4.8.4 QListView - prevent vertical scrolling and resize vertically to contents
-
I have a QListView that has been given a model. Putting the QListView in a layout makes it squeeze its height, so that it shows only part of the items from the model and the vertical scrollbar appears that allows for browsing the rest of the items. This behavior is due to its QAbstractScrollArea nature.
What I want is that the QListView resizes vertically, so that it shows all of its items.
@
QAbstractScrollArea::setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
@only removes the scrollbar, but doesn't make the list view resize vertically to its contents.
Any suggestions?
-
you will need to ensure this by yourself. Meaning to listen to model signals for data changes and resize the listview.
You can use QAbsractItemView::visualRect() and sum up the height for all indexes in the view/model.