如何从Qt设计器初始化python代码

时间:2016-04-27 07:45:07

标签: python qt

我必须为我正在进行的项目制作GUI。由于我不是程序员,请原谅我的问题。

我使用Qt-designer创建了GUI。我还成功地将.ui文件编译为.py

from PySide import QtCore, QtGui

class Ui_Mesher(object):
    def setupUi(self, Mesher):
        Mesher.setObjectName("Mesher")
        Mesher.resize(480, 555)
        self.pushButton = QtGui.QPushButton(Mesher)
        self.pushButton.setGeometry(QtCore.QRect(130, 510, 101, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtGui.QPushButton(Mesher)
        self.pushButton_2.setGeometry(QtCore.QRect(240, 510, 101, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_3 = QtGui.QPushButton(Mesher)
        self.pushButton_3.setGeometry(QtCore.QRect(320, 450, 75, 23))
        self.pushButton_3.setObjectName("pushButton_3")
        self.comboBox = QtGui.QComboBox(Mesher)
        self.comboBox.setGeometry(QtCore.QRect(10, 450, 131, 22))
        self.comboBox.setAcceptDrops(False)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.groupBox = QtGui.QGroupBox(Mesher)
        self.groupBox.setGeometry(QtCore.QRect(10, 10, 461, 351))
        self.groupBox.setObjectName("groupBox")
        self.add_coordinates_button = QtGui.QPushButton(self.groupBox)
        self.add_coordinates_button.setGeometry(QtCore.QRect(190, 100, 51, 41))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("../../Icons/green-right-arrow-clip-art-6842.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.add_coordinates_button.setIcon(icon)
        self.add_coordinates_button.setObjectName("add_coordinates_button")
        self.list_coordinates = QtGui.QListWidget(self.groupBox)
        self.list_coordinates.setGeometry(QtCore.QRect(280, 20, 161, 192))
        self.list_coordinates.setObjectName("list_coordinates")
        self.input_x_coordinate = QtGui.QLineEdit(self.groupBox)
        self.input_x_coordinate.setGeometry(QtCore.QRect(40, 110, 51, 20))
        self.input_x_coordinate.setObjectName("input_x_coordinate")
        self.input_y_coordinate = QtGui.QLineEdit(self.groupBox)
        self.input_y_coordinate.setGeometry(QtCore.QRect(100, 110, 51, 20))
        self.input_y_coordinate.setObjectName("input_y_coordinate")

        self.retranslateUi(Mesher)
        QtCore.QMetaObject.connectSlotsByName(Mesher)

        def retranslateUi(self, Mesher):
            Mesher.setWindowTitle(QtGui.QApplication.translate("Mesher", "Mesher", None, QtGui.QApplication.UnicodeUTF8))
            self.pushButton.setText(QtGui.QApplication.translate("Mesher", "Save Changes", None, QtGui.QApplication.UnicodeUTF8))
            self.pushButton_2.setText(QtGui.QApplication.translate("Mesher", "Exit", None, QtGui.QApplication.UnicodeUTF8))
            self.pushButton_3.setText(QtGui.QApplication.translate("Mesher", "Import", None, QtGui.QApplication.UnicodeUTF8))
            self.comboBox.setItemText(0, QtGui.QApplication.translate("Mesher", "Engrid", None, QtGui.QApplication.UnicodeUTF8))
            self.comboBox.setItemText(1, QtGui.QApplication.translate("Mesher", "Gmsh", None, QtGui.QApplication.UnicodeUTF8))
            self.comboBox.setItemText(2, QtGui.QApplication.translate("Mesher", "Salome", None, QtGui.QApplication.UnicodeUTF8))
            self.comboBox.setItemText(3, QtGui.QApplication.translate("Mesher", "Abaqus", None, QtGui.QApplication.UnicodeUTF8))
            self.comboBox.setItemText(4, QtGui.QApplication.translate("Mesher", "Ansys", None, QtGui.QApplication.UnicodeUTF8))
            self.groupBox.setTitle(QtGui.QApplication.translate("Mesher", "EzMesher", None, QtGui.QApplication.UnicodeUTF8))
            self.add_coordinates_button.setText(QtGui.QApplication.translate("Mesher", "Create geometry", None, QtGui.QApplication.UnicodeUTF8))


Ui_Mesher()

我试图在我的主文件中初始化它,如:

from PySide.QtCore import *
from PySide.QtGui import *
import sys

import Gui_mesh

class MainDialog(QDialog, Gui_mesh.Ui_mainDialog):

def __init__(self, parent = None):

    super(MainDialog, self).__init__(parent)
    self.setupUi(self)

app = QApplication(sys.argv)
form = MainDialog()
form.show()
app.exec_()

但显然我无法使用Ui_mainDialog。我希望你能帮助我。

此致

1 个答案:

答案 0 :(得分:1)

我认为您应该使用已编译的.py文件中的正确名称?

class MainDialog(QDialog, Gui_mesh.Ui_Mesher)