我在Qt Designer中有一個按鈕,我希望它總是佔用與它需要的文本一樣多的空間。我怎麼能做到這一點?Qt按鈕需要佔用足夠的空間作爲它需要的文本
我的意思是像按鈕上的文字是「你好」,按鈕將是45px。
當我做self.button.setText("Hello World")
該按鈕將是85px。
我目前的 「servers.ui」:
<item>
<widget class="QPushButton" name="pageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
,我實際上是在談論:
嘗試在更改文本後調用updateGeometry http://doc.qt.io/qt-4.8/qwidget.html#updateGeometry – Chris
像這樣https://i.imgur.com/S5N1JN0.png?它仍然被切斷。 – Bluscream
Designer中的設置:https://i.imgur.com/A5nqzlK.png – Bluscream