如何使用 PyQt 制作可变列网格

如何使用 PyQt 制作可变列网格

问题描述:

我正在尝试使用 Python 和 Qt4 显示一组图像缩略图.我的问题是我不想计算网格的列数,因此当应用程序调整大小或我的缩略图变大时,列数会自动更改.实际上我想使用 Qlabel,因为图像将具有文件名和可能的按钮.有什么简单的方法吗?

I'm trying to display an array of image thumbnails using Python and Qt4. My problem is that I don't want to calculate the amount of columns for the grid, so that when the application is resized or my thumbnails get bigger, the number of columns automatically change. Actually I want to use Qlabel, because images are going to have file names and possibly buttons. Is there an easy way to do it?

类似的东西:

Brendan Abel 的答案是使用 Qt 功能的正确而优雅的方式.但是,如果您发现模型视图架构过于繁重,我建议您使用 这里.

Brendan Abel's answer is the right and elegant way to use the power of Qt. However, if you find model-view architecture too heavy, I'd suggest you to use FlowLayout demonstrated in here.

它相当容易实施并且可能适合您的需求.

Its rather quite easy to implement and may suit your needs.