Qt Resize of QListView

2.2k Views Asked by At

I would like to adjust a QListView's width according to its content to let every item visible. The list is like:

...
setFlow(QListView::LeftToRight) ;
setLayoutMode(QListView::Batched);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAutoScroll(false);
setUniformItemSizes(true);
setResizeMode(QListView::Adjust);
...

I tried different QSizePolicy and got really confused.

1

There are 1 best solutions below

0
On

This switch:

setUniformItemSizes(true);

turns on some optimizations of the QListView. Seems like the optimized code does not calculate the layout when qlistview is resized. Try setting setUniformItemSizes(false) and your qlistview should adapt to the item sizes.