以下は、私の問題を示す非常に単純な Qt ui ファイルです。(Windows 7 64 ビットで Qt 4.8.0 を使用)
問題を再現するには、Windows のデザイナでファイルをロードし (他の OS でも発生する可能性があります)、ctrl+R を押して、ファイルに記述されたダイアログを表示します。編集フィールドに入力を開始し、右下隅をつかんでダイアログのサイズを変更します。ダイアログのサイズは、予期されるラベルの新しいテキストに合わせてポップされます。期待されていないのは、行編集に入力した意味不明な内容に応じて、ラベルの下部にさまざまな量のスペースがあることです (場合によっては多い場合も少ない場合もあります)。
wordWrap QLabel は、基本的に幅が固定されているのに、どのくらいの高さにすべきかについて混乱するのはなぜですか?
test.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>86</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>360</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>360</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="lineEdit"/>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>lineEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>label</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>120</x>
<y>14</y>
</hint>
<hint type="destinationlabel">
<x>146</x>
<y>47</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>304</x>
<y>76</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>85</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>236</x>
<y>76</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>85</y>
</hint>
</hints>
</connection>
</connections>
</ui>