更改 Qt 布局中的调整大小行为 [英] Change resize behavior in Qt layouts

查看:57
本文介绍了更改 Qt 布局中的调整大小行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的自定义小部件在调整对话框大小时获得额外空间.当我只有少数小部件时,这是有效的,但是在添加更多这些相同小部件的列并将它们放入 QGridLayout 后,额外的空间仅作为小部件之间的填充.

I want my custom widgets to gain extra space when the dialog is resized. This was working when I only had a handful of widgets, but after adding several more columns of these same widgets and putting them in a QGridLayout, the extra space merely goes in as padding between the widgets.

推荐答案

我过去遇到过这个问题,以下是我发现的一些问题:

I've had trouble with this in the past and here are some of the things I've found:

  1. 首先确保您要扩展的所有小部件都将 sizePolicy 设置为扩展".

  1. First make sure all the widgets you want to expand have sizePolicy set to "Expanding".

确保组成您的自定义小部件的小部件位于允许扩展的布局中.您只需将一个自定义小部件添加到窗口并查看它是否按预期展开即可检查这一点.

Make sure the widgets that make up your custom widgets are in a layout that allows for expanding. You can check this by just adding one of your custom widgets to the window and seeing that it expands as expected.

确保表单上任何您不想展开的小部件在您希望它们保持静态的维度上具有固定(最小=最大)尺寸.

Make sure any widgets on the form that you do not want to expand have a fixed (minimum=maximum) size in the dimension you want them to stay static.

有时网格布局会导致一些奇怪的间距问题,因为行会根据整行中最大的小部件调整大小,列也类似.对于某些布局,最好使用包含水平布局的垂直布局,反之亦然,以创建类似网格的效果.只有这样,每个子布局才能独立于其他行或列.

Sometimes the grid layout causes some weird spacing issues because rows are resized based on the largest widget in the entire row and similarly for columns. For some layouts, it is better to use a vertical layout that contains horizontal layouts or vica versa to create a grid-like effect. Only this way, each sub-layout is spaced independently of the other rows or columns.

这篇关于更改 Qt 布局中的调整大小行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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