在QT / PYQT中使用布局

时间:2016-06-26 18:09:34

标签: python qt pyqt

所以我写了这个程序,一切正常,但我想添加一个"布局"清理一下。但是,当我这样做然后去运行它时,它告诉我已经有一个布局或格式,并且所有小部件在右上角显示在彼此的顶部。我错过了什么

import sys

from PyQt4 import QtCore, QtGui, uic
form_class = uic.loadUiType("/Users/Home/Desktop/Timer/timer.ui")[0]   # Load the UI



class MyWindowClass(QtGui.QMainWindow, form_class):
   def __init__(self, parent=None):
       QtGui.QMainWindow.__init__(self, parent)
       self.setupUi(self)
       self.start_btn = self.startButton
       self.start_btn.clicked.connect(self.tick)

   def tick(self):
       start_time = int(self.timeStart.text())
       stop_time = int(self.timeStop.text())
       orders = int(self.tot_orders.text())
       hours = int((stop_time - start_time) / 100)
       if hours > 2:
           hours = hours - 0.25
       elif hours > 5:
           hours = hours - 0.45
       elif hours > 7:
           hours = hours - 1
       speed = orders / hours
       str_speed = "{:.2f}".format(speed)
       output = (str_speed+" orders per hour")
       self.progressLbl.setText(output)

app = QtGui.QApplication(sys.argv)
myWindow = MyWindowClass(None)
myWindow.show()
app.exec_()

1 个答案:

答案 0 :(得分:0)

布局应该是ui文件的一部分,所以你应该使用Qt Designer来添加它。

有关基本概述,请参阅:Using Layouts in Qt Designer