QLabel wordWrap设置产生意外的sizeHint

时间:2012-10-26 00:08:07

标签: c++ qt qt4.8

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

要重现此问题,请在Windows上的设计器中加载文件(也可能在其他操作系统上),然后按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>

0 个答案:

没有答案