问题描述
基本上,我有一个QGridLayout
,里面有一些小部件.重要的是2个标签,我将它们用于将图像绘制到屏幕上.好吧,如果用户愿意,他可以更改传入图像的分辨率,从而强制调整标签的大小.
Basically I've got a QGridLayout
with a few widgets in it. The important ones are 2 labels, which I use for drawing images to the screen. Well, if the user wants, he can change the resolution of the incoming images, thus, forcing the Labels to resize.
让我们假设标签的初始尺寸为320x240
.用户将VideoMode更改为640x480
,标签和整个GUI的大小都会完美调整.但是,当用户切换回320x240
时,标签会缩小,但布局/窗口不会.
Let's assume the initial size of the label is 320x240
. The user changes the VideoMode to 640x480
, the label and the entire GUI resizes perfectly. But when the user switches back to 320x240
, the label shrinks, but the Layout/Window does NOT.
我玩过sizePolicies
,sizeHints
和resize(0,0)
,但是没有花招.有人可以帮我吗?
I've played around with sizePolicies
and sizeHints
, and resize(0,0)
, but nothing did the trick. Could somebody help me with this?
这里有一些屏幕截图可以说明问题:
Here some screenshots to clarify the problem:
推荐答案
您需要将包含所有小部件的布局的大小约束设置为"SetFixedSize".尽管该名称听起来并不可行,但可以确保您的布局仅使用所需的空间.您将不会像第二个屏幕截图那样出现问题.
You need to set the size constraint of the layout holding all your widgets to "SetFixedSize". Although the name doesn't sound like it will work, it ensures that your layout will only use the space it needs. You will not have the problem like you do in your second screenshot.
示例:
mainLayout.setSizeConstraint(QLayout::SetFixedSize);
这篇关于Qt布局,更改窗口小部件大小后将其调整为最小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!