我有一个包含具有三列的 QGridLayout 的对话框。其中一行在每一列中分别包含一个 QComboBox、一个 QPushbutton 和另一个 QPushButton。我希望每列的大小和比例相同。
不幸的是,QComboBox 将其大小提示设置得太大,以至于足以容纳其最宽的项目。似乎没有名为“DoNotAdjustAndStopBeingAnnoying”的 SizeAdjustPolicy或类似的,所以我不确定是否可以设置任何内容来强制它停止进行此调整。
我知道我可以相当轻松地在代码中完成此操作,但我更愿意将此类详细信息保留在 .ui 文件中。有什么办法可以在 Qt 4.8 中做到这一点而无需编写任何代码吗?
I have a dialog containing a QGridLayout with three columns. One of the rows contains a QComboBox, a QPushbutton, and another QPushButton in each column respectively. I want each column to be the same size and scale equally.
Unfortunately, the QComboBox is setting its size hint too large, to be big enough to contain its widest item. It appears there's no SizeAdjustPolicy called "DoNotAdjustAndStopBeingAnnoying" or similar, so I'm not sure if there's anything I can set to force it to stop doing this adjusting.
I know I can do this in code fairly easily, but I would prefer to keep this sort of detail in the .ui file. Is there any way I can do this in Qt 4.8 without writing any code?
发布评论
评论(2)
我可以通过将组合框的
sizePolicy
的水平分量设置为Ignored
来解决此问题。这导致组合框能够比按钮进一步缩小,因此我将它们更改为也使用Ignored
并为所有 3 个控件设置水平minimumSize
。现在,它们都以相同的尺寸开始,并随着布局均匀地上下调整尺寸,直到适当的最小值为止。I was able to solve this by setting the horizontal component of the
sizePolicy
for the combo box toIgnored
. That resulted in the combo box becoming able to be shrunk further than the buttons, so I changed them to also useIgnored
and set the horizontalminimumSize
for all 3 of the controls. Now they all start out at the same size, and are sized up and down with the layout equally, stopping at an appropriate minimum.不要在 ui 文件中覆盖它。当您构建可直接访问 ui 的对象时,可以使用 Qt Designer 在属性面板中或在代码中覆盖它。
编辑:无论如何它可能很有用
QLayout 之间存在层次结构: :尺寸约束, QWidget::minimumSizeHint, QWidget::minimumSize,您可以在文档中找到它。
QWidget::minimumSize
。当它出现时,它会压倒一切QWidget::minimumSizeHint
QWidget::minimumSizeHint
无效(意味着可以用鼠标将其大小调整为 0),否则使用由布局定义。QLayout::SizeConstraint
保存它*直接*管理的小部件的默认布局行为。如果您将布局A
嵌套在布局B
中,则添加到A
的所有小部件都将使用其属性。此外,如果B
中的小部件W
定义了自己的布局,则此布局约束将应用于小部件W
。Do not override it in the ui file. Override it either with Qt Designer, in the property panel, or in the code, when you are constructing the object with direct access to the ui.
EDIT: Anyway it can be useful
There is hierarchy between QLayout::SizeConstraint, QWidget::minimumSizeHint, QWidget::minimumSize, and you can find it in the documentation.
QWidget::minimumSize
is not set by default. When it is, it prevails overQWidget::minimumSizeHint
QWidget::minimumSizeHint
is invalid if the widget is not in a layout (meaning that it can be resized to 0 with the mouse), otherwise use the one defined by the layout.QLayout::SizeConstraint
holds the default layout behavior of the widgets it *directly * manage. If you nest a layoutA
within a layoutB
, all widgets added toA
will use its property. Also if a widgetW
inB
define its own layout, then this layout constraints are the one to be applied for the widgetW
.