【问题标题】:QDockwidgets beside each othersQDockwidgets 并排
【发布时间】:2022-01-27 19:12:37
【问题描述】:

如何制作这样的用户界面

我尝试过代码和设计器,但我做不到

谢谢。

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python pyqt5 qt-designer


【解决方案1】:

我能够通过在 qt 设计器中拖放来创建相同的布局 这是带有布局管理器的 UI 代码,并且能够调整停靠点的大小

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Frame</class>
 <widget class="QFrame" name="Frame">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>628</width>
    <height>604</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Frame</string>
  </property>
  <layout class="QHBoxLayout" name="horizontalLayout">
   <item>
    <widget class="QSplitter" name="splitter_2">
     <property name="orientation">
      <enum>Qt::Horizontal</enum>
     </property>
     <widget class="QSplitter" name="splitter">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
      <widget class="QDockWidget" name="dockWidget">
       <property name="minimumSize">
        <size>
         <width>150</width>
         <height>0</height>
        </size>
       </property>
       <property name="styleSheet">
        <string notr="true">background-color: rgb(0, 0, 0);</string>
       </property>
       <widget class="QWidget" name="dockWidgetContents"/>
      </widget>
      <widget class="QDockWidget" name="dockWidget_2">
       <property name="minimumSize">
        <size>
         <width>150</width>
         <height>0</height>
        </size>
       </property>
       <property name="styleSheet">
        <string notr="true">background-color: rgb(32, 74, 135);</string>
       </property>
       <widget class="QWidget" name="dockWidgetContents_2"/>
      </widget>
     </widget>
     <widget class="QFrame" name="frame">
      <property name="frameShape">
       <enum>QFrame::NoFrame</enum>
      </property>
      <property name="frameShadow">
       <enum>QFrame::Raised</enum>
      </property>
     </widget>
     <widget class="QDockWidget" name="dockWidget_4">
      <property name="minimumSize">
       <size>
        <width>120</width>
        <height>581</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(239, 41, 41);</string>
      </property>
      <widget class="QWidget" name="dockWidgetContents_4"/>
     </widget>
     <widget class="QDockWidget" name="dockWidget_3">
      <property name="minimumSize">
       <size>
        <width>120</width>
        <height>581</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(115, 210, 22);</string>
      </property>
      <widget class="QWidget" name="dockWidgetContents_3"/>
     </widget>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

将其保存到文件后,您可以通过运行将其更改为 py 文件

pyuic5 -x file.ui -o file.py

或者像cmets中musicamante所说的那样直接和uic模块一起使用

【讨论】:

  • 这似乎不是一个好的结果:没有设置layout manager,一旦调整窗口大小,停靠栏就会被隐藏,或者窗口的许多部分会不必要地为空。您应该正确设置主布局in Designer。另外,不需要pyuic这一步,只要使用uic模块即可。
  • @musicamante 那么应该是这样的
猜你喜欢
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 2019-08-03
  • 2018-01-17
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 2011-03-01
相关资源
最近更新 更多