Pyqt没有正确显示QT应用程序

时间:2017-04-17 22:17:59

标签: qt pyqt python-3.5

我正在设计一个简单的GUI来执行某些操作,并且在很早的阶段我发现QT的行为并不像我期望的那样。我在QT Design中设计了ui文件,它看起来像这样: enter image description here

然而,当我执行python代码并调用应用程序时,对象位置都被更改了。我已经尝试将ui文件转换为python文件并直接导入ui文件。但这并没有改变这种行为。

以下是代码:

from __future__ import (
    unicode_literals,
    print_function,
    division,
    absolute_import
)
from PyQt4 import QtGui, QtCore, uic
from PyQt4.QtCore import QTime
from PyQt4.QtGui import QApplication
import main_gui


# class MyGUI(QtGui.QMainWindow, main_gui.Ui_MainWindow):
class MyGUI(QtGui.QMainWindow):
    """
    The main class to execute the application
    """
    def __init__(self, parent=None):
        super(MyGUI, self).__init__(parent)
        uic.loadUi('main_gui.ui', self)
        # self.setupUi(self)
        # self.showMaximized()


def main():
    """
    But first we'll need to initialize that class on our code startup,
    we'll handle the class instance creation and other stuff in our main()
    function:
    :return: Nothing
    """
    app = QtGui.QApplication([])
    form = MyGUI()
    form.show()
    app.exec()


if __name__ == '__main__':
    main()

输出如下: enter image description here

以下是我的设计师的截图:

enter image description here

我做错了什么?

编辑: 根据要求,我附上了main.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>1143</width>
    <height>865</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <widget class="Line" name="line_10">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QLabel" name="title">
          <property name="minimumSize">
           <size>
            <width>200</width>
            <height>40</height>
           </size>
          </property>
          <property name="font">
           <font>
            <pointsize>20</pointsize>
           </font>
          </property>
          <property name="mouseTracking">
           <bool>false</bool>
          </property>
          <property name="text">
           <string>Title</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignBottom|Qt::AlignHCenter</set>
          </property>
         </widget>
        </item>
        <item>
         <widget class="Line" name="line">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </widget>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_2">
          <item alignment="Qt::AlignLeft|Qt::AlignVCenter">
           <widget class="QLabel" name="label_2">
            <property name="font">
             <font>
              <pointsize>24</pointsize>
             </font>
            </property>
            <property name="text">
             <string>SN</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="Line" name="line_6">
            <property name="orientation">
             <enum>Qt::Vertical</enum>
            </property>
           </widget>
          </item>
          <item alignment="Qt::AlignRight|Qt::AlignVCenter">
           <widget class="QLabel" name="sn">
            <property name="font">
             <font>
              <pointsize>18</pointsize>
             </font>
            </property>
            <property name="text">
             <string>PPPPPPPPPPPPPPGSDB1YYDDDHHMMSS</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <widget class="Line" name="line_2">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </widget>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_3">
          <item alignment="Qt::AlignLeft|Qt::AlignVCenter">
           <widget class="QLabel" name="label_4">
            <property name="font">
             <font>
              <pointsize>18</pointsize>
             </font>
            </property>
            <property name="text">
             <string>Part Status</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="Line" name="line_7">
            <property name="orientation">
             <enum>Qt::Vertical</enum>
            </property>
           </widget>
          </item>
          <item alignment="Qt::AlignRight|Qt::AlignVCenter">
           <widget class="QLabel" name="part_status">
            <property name="font">
             <font>
              <pointsize>26</pointsize>
             </font>
            </property>
            <property name="text">
             <string>NA</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <widget class="Line" name="line_3">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </widget>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_4">
          <item alignment="Qt::AlignLeft|Qt::AlignVCenter">
           <widget class="QLabel" name="label_7">
            <property name="font">
             <font>
              <pointsize>18</pointsize>
             </font>
            </property>
            <property name="text">
             <string>Tester Status</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="Line" name="line_8">
            <property name="orientation">
             <enum>Qt::Vertical</enum>
            </property>
           </widget>
          </item>
          <item alignment="Qt::AlignRight|Qt::AlignVCenter">
           <widget class="QLabel" name="tester_status">
            <property name="font">
             <font>
              <pointsize>28</pointsize>
             </font>
            </property>
            <property name="text">
             <string>DOWN</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <widget class="Line" name="line_4">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </widget>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_5">
          <item alignment="Qt::AlignLeft|Qt::AlignVCenter">
           <widget class="QLabel" name="label_9">
            <property name="font">
             <font>
              <pointsize>18</pointsize>
             </font>
            </property>
            <property name="text">
             <string>IP Address</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="Line" name="line_9">
            <property name="orientation">
             <enum>Qt::Vertical</enum>
            </property>
           </widget>
          </item>
          <item alignment="Qt::AlignRight|Qt::AlignVCenter">
           <widget class="QLabel" name="ip_address">
            <property name="font">
             <font>
              <pointsize>24</pointsize>
             </font>
            </property>
            <property name="text">
             <string>NA</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
       </layout>
      </item>
      <item>
       <widget class="Line" name="line_5">
        <property name="orientation">
         <enum>Qt::Vertical</enum>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QTextBrowser" name="test_box"/>
      </item>
     </layout>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1143</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

0 个答案:

没有答案