3

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.

4

1 回答 1

0

这个开关:

setUniformItemSizes(true);

打开 QListView 的一些优化。似乎优化的代码在调整 qlistview 大小时不会计算布局。尝试设置 setUniformItemSizes(false) 并且您的 qlistview 应该适应项目大小。

于 2016-12-10T21:43:15.307 回答