How do I tell QListView to resize to fit?

我们两清 提交于 2019-12-20 04:47:24

问题


I have a QListView and have assigned a model and a delegate. I am using it to display images in a horizontal bar as below

On a user event, data is updated in the model. One such event causes the width of the images to be reduced like below(#4).

I emit a dataChanged on the corresponding index and only the concerned widget is repainted. Because of this, there is a gap between #4 and #5 which does not get filled. I am thinking that there must be a way to refresh all visible rows - but am unable to find it.

I tried the following, but they do not work:

1. viewport()->updateGeometries()

2. viewport()->update()

3. I tried changing the width to see if it refreshes
    int curWidth = mp_mylistview->width();
    this->mp_mylistview->setFixedWidth(curWidth + 1);
    this->mp_mylistview->setFixedWidth(curWidth);

Any suggestions?

Note: The above images are samples for illustration and not the originals. If you need code, I will need to filter out confidential information before posting it.


回答1:


All I had to do was to emit layoutChanged() as a follow up to the dataChanged().



来源:https://stackoverflow.com/questions/14563499/how-do-i-tell-qlistview-to-resize-to-fit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!