2

下面是一个非常简单的 Qt ui 文件来显示我的问题。(在 Windows 7 64 位上使用 Qt 4.8.0)

要重现该问题,请在 Windows 上的设计器中加载文件(也可能在其他操作系统上发生)并按 ctrl+R 以显示文件描述的对话框。开始在编辑字段中输入,然后抓住右下角来调整对话框的大小。对话框的大小将弹出以适合标签的预期新文本。出乎意料的是,标签底部有可变数量的空间,具体取决于您在行编辑中输入的乱码(有时更多,有时更少)。

当 wordWrap QLabel 基本上具有固定宽度时,为什么它会对它应该有多高感到困惑?

测试.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>
4

0 回答 0