如何告诉QListView调整大小以适应? [英] How do I tell QListView to resize to fit?

查看:1697
本文介绍了如何告诉QListView调整大小以适应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QListView并分配了一个模型和一个委托.我正在用它在下面的水平栏中显示图像

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

在用户事件中,数据将在模型中更新.一种这样的事件导致图像的宽度减小,如下所示(#4).

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).

我在相应的索引上发出一个dataChanged,并且仅重绘了相关的窗口小部件.因此,在#4和#5之间没有填补空白.我认为必须有一种刷新所有可见行的方法-但找不到它.

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);

有什么建议吗?

注意:上面的图像是用于示例的样本,而非原始图像.如果您需要代码,我将需要在发布前过滤掉机密信息.

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.

推荐答案

我要做的就是对emit layoutChanged()做为dataChanged()的后续工作.

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

这篇关于如何告诉QListView调整大小以适应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆