【问题标题】:Make content and tab expandable in pyqt5在 pyqt5 中使内容和选项卡可扩展
【发布时间】:2019-08-06 17:03:44
【问题描述】:

这是我试图在 QT Creator 中解决的问题。我想让标签小部件的内容以及标签小部件本身可以根据屏幕大小进行拉伸。到目前为止,我一直在 StackOverflow 上寻找解决方案,但找不到任何解决方案。

一个小例子:

正如其他答案中所建议的,我将所有内容组织在具有这些属性的网格布局中。

事实上,我什至为列表中的所有对象添加了相同的Expanding 值。但是尽管如此,当我以全屏尺寸打开它时,我仍然会得到一个固定的标签小部件。

有什么建议可以让标签小部件填满周围的所有空间吗?提前致谢!

UPD 1: 也分享我的 .ui https://gist.github.com/Ren22/41ca0dc0333a360775aec530d6f38a62

【问题讨论】:

    标签: python pyqt pyqt5 qt-designer qtabwidget


    【解决方案1】:

    大小策略仅在小部件几何由布局处理时才有效,因此解决方案是将 QTabWidget 设置为 centralwidget 以右键单击 QTabWidget 之外但在 QMainWindow 内的区域,然后单击Qt Designer 顶部的图标 ​​ 图标生成以下内容:

    <?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>800</width>
        <height>600</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralwidget">
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <widget class="QTabWidget" name="tabWidget">
          <widget class="QWidget" name="tab">
           <attribute name="title">
            <string>Tab 1</string>
           </attribute>
           <layout class="QVBoxLayout" name="verticalLayout_2">
            <item>
             <widget class="QListWidget" name="listWidget"/>
            </item>
            <item>
             <widget class="QPushButton" name="pushButton">
              <property name="text">
               <string>PushButton</string>
              </property>
             </widget>
            </item>
           </layout>
          </widget>
          <widget class="QWidget" name="tab_2">
           <attribute name="title">
            <string>Tab 2</string>
           </attribute>
          </widget>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QMenuBar" name="menubar">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>800</width>
         <height>30</height>
        </rect>
       </property>
      </widget>
      <widget class="QStatusBar" name="statusbar"/>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    【讨论】:

    • 太棒了,再次感谢。我想这一切都在我需要阅读的文档中注明
    猜你喜欢
    • 2017-01-12
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    相关资源
    最近更新 更多