Skip to main content
 首页 » 编程设计

python之使用 pyuic 运行时,PyQt5 对话框小部件看起来有问题

2025年04月02日36xing901022

所以我在 PyQt5 中制作了一个应用程序,它有一个对话框。但是当使用 pyuic 运行时,对话框看起来确实有问题。

这是一段视频:https://youtu.be/3oJ7EMiJxO0 如您所见,对话框在“预览”功能下显示良好,但当我使用 python 和 pyuic 运行它时,标签和下拉菜单出现无法使用的故障。虽然按钮似乎工作正常......

我正在使用 GNOME 3 和 Python 2.7 运行 Fedora 23 Workstation。

这是我的 .ui 文件的内容...

<?xml version="1.0" encoding="UTF-8"?> 
<ui version="4.0"> 
 <author>David Teresi</author> 
 <class>Dialog</class> 
 <widget class="QDialog" name="Dialog"> 
  <property name="enabled"> 
   <bool>true</bool> 
  </property> 
  <property name="geometry"> 
   <rect> 
    <x>0</x> 
    <y>0</y> 
    <width>258</width> 
    <height>300</height> 
   </rect> 
  </property> 
  <property name="windowTitle"> 
   <string>backflip Settings</string> 
  </property> 
  <property name="autoFillBackground"> 
   <bool>false</bool> 
  </property> 
  <property name="sizeGripEnabled"> 
   <bool>false</bool> 
  </property> 
  <widget class="QDialogButtonBox" name="buttonBox"> 
   <property name="geometry"> 
    <rect> 
     <x>-90</x> 
     <y>260</y> 
     <width>341</width> 
     <height>32</height> 
    </rect> 
   </property> 
   <property name="orientation"> 
    <enum>Qt::Horizontal</enum> 
   </property> 
   <property name="standardButtons"> 
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> 
   </property> 
  </widget> 
  <widget class="QGroupBox" name="groupBox"> 
   <property name="geometry"> 
    <rect> 
     <x>10</x> 
     <y>0</y> 
     <width>241</width> 
     <height>261</height> 
    </rect> 
   </property> 
   <property name="title"> 
    <string>backflip Settings</string> 
   </property> 
   <widget class="QWidget" name="layoutWidget"> 
    <property name="geometry"> 
     <rect> 
      <x>10</x> 
      <y>60</y> 
      <width>155</width> 
      <height>22</height> 
     </rect> 
    </property> 
    <layout class="QHBoxLayout" name="horizontalLayout_2"> 
     <item> 
      <widget class="QLabel" name="UpdateEveryLabel"> 
       <property name="text"> 
        <string>Update every</string> 
       </property> 
      </widget> 
     </item> 
     <item> 
      <widget class="QComboBox" name="UpdateEverySelect"> 
       <property name="contextMenuPolicy"> 
        <enum>Qt::DefaultContextMenu</enum> 
       </property> 
       <item> 
        <property name="text"> 
         <string>Day</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Week</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Hour</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Minute</string> 
        </property> 
       </item> 
      </widget> 
     </item> 
    </layout> 
   </widget> 
   <widget class="QPushButton" name="RefreshButton"> 
    <property name="geometry"> 
     <rect> 
      <x>10</x> 
      <y>230</y> 
      <width>75</width> 
      <height>23</height> 
     </rect> 
    </property> 
    <property name="text"> 
     <string>Refresh</string> 
    </property> 
   </widget> 
   <widget class="QWidget" name=""> 
    <property name="geometry"> 
     <rect> 
      <x>10</x> 
      <y>20</y> 
      <width>109</width> 
      <height>22</height> 
     </rect> 
    </property> 
    <layout class="QHBoxLayout" name="horizontalLayout"> 
     <item> 
      <widget class="QLabel" name="ThemeLabel"> 
       <property name="text"> 
        <string>Theme</string> 
       </property> 
      </widget> 
     </item> 
     <item> 
      <widget class="QComboBox" name="ThemeSelect"> 
       <property name="contextMenuPolicy"> 
        <enum>Qt::DefaultContextMenu</enum> 
       </property> 
       <item> 
        <property name="text"> 
         <string>None</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Buildings</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Food</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Nature</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>Technology</string> 
        </property> 
       </item> 
       <item> 
        <property name="text"> 
         <string>People</string> 
        </property> 
       </item> 
      </widget> 
     </item> 
    </layout> 
   </widget> 
  </widget> 
 </widget> 
 <resources/> 
 <connections> 
  <connection> 
   <sender>buttonBox</sender> 
   <signal>accepted()</signal> 
   <receiver>Dialog</receiver> 
   <slot>accept()</slot> 
   <hints> 
    <hint type="sourcelabel"> 
     <x>248</x> 
     <y>254</y> 
    </hint> 
    <hint type="destinationlabel"> 
     <x>157</x> 
     <y>274</y> 
    </hint> 
   </hints> 
  </connection> 
  <connection> 
   <sender>buttonBox</sender> 
   <signal>rejected()</signal> 
   <receiver>Dialog</receiver> 
   <slot>reject()</slot> 
   <hints> 
    <hint type="sourcelabel"> 
     <x>316</x> 
     <y>260</y> 
    </hint> 
    <hint type="destinationlabel"> 
     <x>286</x> 
     <y>274</y> 
    </hint> 
   </hints> 
  </connection> 
 </connections> 
</ui> 

有人可以帮我吗?

请您参考如下方法:

我可以从您的 Designer 文件中看到您的 QDialog 或 QGroupBox 都没有分配布局。他们应该使用QVBoxLayout。您可能还需要添加一些垂直间隔符。