首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Qt-designer初始化python代码

如何从Qt-designer初始化python代码
EN

Stack Overflow用户
提问于 2016-04-27 07:45:06
回答 1查看 304关注 0票数 0

我必须为我正在做的项目做一个GUI。既然我不是程序员,请原谅我的问题。

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

代码语言:javascript
复制
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()

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

代码语言:javascript
复制
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。我希望你能帮助我。

问候

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-27 07:56:26

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

代码语言:javascript
复制
class MainDialog(QDialog, Gui_mesh.Ui_Mesher)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36883466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档