2

Below is a very simple Qt ui file to show my issue. (using Qt 4.8.0 on Windows 7 64bit)

To reproduce the problem, load the file in designer on Windows (may happen on other OS's too) and press ctrl+R to display the dialog described by the file. Start typing in the edit field and then grab the lower right corner to resize the dialog. The size of the dialog will pop to fit the label's new text which is expected. What's not expected is that there is a variable amount of space at the bottom of the label depending on what gibberish you typed into the line edit (sometimes more, sometimes less).

Why does a wordWrap QLabel get so confused as to how tall it should be when it basically has a fixed width?

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>
cppguy
  • 3,611
  • 2
  • 21
  • 36

0 Answers0