Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 为什么为QLabel启用word wrap会改变布局?_Qt_Pyside_Qlabel - Fatal编程技术网

Qt 为什么为QLabel启用word wrap会改变布局?

Qt 为什么为QLabel启用word wrap会改变布局?,qt,pyside,qlabel,Qt,Pyside,Qlabel,所以我有一个用Qt Designer制作的小程序,在大多数情况下,它是完全好的。但有一个琐碎的问题 我有一个QLabel,它的文本有时太长,所以我想让文本换行。这应该是一项简单的任务 以下是没有文字包装的情况下的外观 这很好。但是,当文本变得太长时,就会出现一个可怕的滚动条。我不想要这个,所以我启用了wordwrap。但接下来会发生这样的情况: 起初我认为Qt设计器是垃圾,所以编译并运行它,希望它能消失。有时会发生这种情况,所以我认为这是一个合理的假设 事实并非如此 这到底是为什么 编辑:

所以我有一个用Qt Designer制作的小程序,在大多数情况下,它是完全好的。但有一个琐碎的问题

我有一个
QLabel
,它的文本有时太长,所以我想让文本换行。这应该是一项简单的任务

以下是没有文字包装的情况下的外观

这很好。但是,当文本变得太长时,就会出现一个可怕的滚动条。我不想要这个,所以我启用了wordwrap。但接下来会发生这样的情况:

起初我认为Qt设计器是垃圾,所以编译并运行它,希望它能消失。有时会发生这种情况,所以我认为这是一个合理的假设

事实并非如此

这到底是为什么

编辑:在小部件初始化器中手动启用word wrap也会导致相同的行为-因此这不是由Qt Designer引起的,而是其他地方的问题。任何帮助都将不胜感激

以下是UI文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>705</width>
    <height>347</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Title</string>
  </property>
  <property name="windowIcon">
   <iconset resource="icons.qrc">
    <normaloff>:/icons/icons/3/bonus48x48_20.png</normaloff>:/icons/icons/3/bonus48x48_20.png</iconset>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,1">
    <item row="1" column="0">
     <widget class="QLabel" name="label_molecule">
      <property name="text">
       <string>Molecule:</string>
      </property>
     </widget>
    </item>
    <item row="1" column="1">
     <widget class="QLineEdit" name="lineEdit_molecule"/>
    </item>
    <item row="2" column="0" colspan="2">
     <widget class="QToolBox" name="toolBox_modelDetails">
      <property name="currentIndex">
       <number>0</number>
      </property>
      <widget class="QWidget" name="page_isomer">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>373</width>
         <height>154</height>
        </rect>
       </property>
       <attribute name="label">
        <string>Isomer</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <widget class="QListWidget" name="listWidget_isomers">
          <property name="alternatingRowColors">
           <bool>true</bool>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QWidget" name="page_model">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>357</width>
         <height>231</height>
        </rect>
       </property>
       <attribute name="label">
        <string>Model</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0">
        <item>
         <widget class="QListWidget" name="listWidget_models">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
          </property>
          <property name="font">
           <font>
            <stylestrategy>PreferDefault</stylestrategy>
           </font>
          </property>
          <property name="lineWidth">
           <number>1</number>
          </property>
          <property name="alternatingRowColors">
           <bool>true</bool>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QLabel" name="label_description">
          <property name="text">
           <string>Howdy!</string>
          </property>
          <property name="wordWrap">
           <bool>true</bool>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QWidget" name="page_basisSet">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>373</width>
         <height>154</height>
        </rect>
       </property>
       <attribute name="label">
        <string>Basis Set</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_3">
        <item>
         <widget class="QListWidget" name="listWidget_basisSets">
          <property name="alternatingRowColors">
           <bool>true</bool>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
     </widget>
    </item>
    <item row="3" column="0" colspan="3">
     <layout class="QHBoxLayout" name="horizontalLayout_buttons">
      <item>
       <spacer name="horizontalSpacer_buttons">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>40</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item>
       <widget class="QPushButton" name="pushButton_save">
        <property name="text">
         <string>Save Input File</string>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QPushButton" name="pushButton_open">
        <property name="text">
         <string>Open</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
    <item row="1" column="2" rowspan="2">
     <widget class="QGroupBox" name="groupBox_MoleculeViewer">
      <property name="title">
       <string>Molecule</string>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources>
  <include location="icons.qrc"/>
 </resources>
 <connections/>
</ui>

主窗口
0
0
705
347
标题
:/icons/icons/3/bonus48x48_20.png:/icons/icons/3/bonus48x48_20.png
分子:
0
0
0
373
154
异构体
真的
0
0
357
231
模型
0
0
优先违约
1.
真的
你好!
真的
0
0
373
154
基集
真的
Qt::水平
40
20
保存输入文件
打开
分子

为什么要将小部件(QLabel和QListWidget)嵌套到
QWidget

这就是为什么你会得到两个滚动条。一个来自
QListWidget
,因为它包含的项目比可以查看的项目多。一个用于父
QWidget

你应该使用

这就是你所拥有的:

应该是这样的:


QLabel与换行和布局相结合,提供了一些有趣的行为。
看。

我不明白。。。您的问题与ListView有关吗?尝试改进ListView最小大小和大小策略。或请提供一个复制此行为的示例代码。外部滚动条来自何处?请发布UI文件内容。我稍后将在引导到unix时发布UI文件。@Frankosterfield内部滚动条用于列表视图,外部列表视图用于工具箱。我希望在列表视图中有一个滚动条,并设置它的大小以使其适合工具箱页面。它嵌套的“小部件”是QToolBox页面。