如题,我使用的是pyside6进行设计界面,通过添加布局实现了自动缩放的界面,但遇到了一个很诡异的现象,就是窗口无法缩小,在QT设计师界面,在geometry属性那里怎么修改,一点确定之后宽度和高度都是原来的值,无法修改窗口大小。然后生成界面运行之后也无法修改。
然后我将界面.ui文件用notepad++打开之后,大家有发现什么问题吗?
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>1024</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>2000</width>
<height>3000</height>
</size>
</property>
是的,里面少了minimumSize属性,于是我又添加了这个属性如下:
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>1024</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>2000</width>
<height>3000</height>
</size>
</property>
结果还是不行,这时我有将minimunSize属性设置了一个初始值为100,如下
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>1024</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>2000</width>
<height>3000</height>
</size>
</property>
然后保存之后,奇迹发生了,不管是在QT设计师还是运行之后都可以缩小窗口了。

博主分享在使用pyside6创建界面时遇到窗口无法缩放的问题,通过探索UI文件发现缺少minimumSize属性。最终调整后,窗口缩放得以解决,揭示了设置最小尺寸对界面缩放的关键作用。
1862

被折叠的 条评论
为什么被折叠?



