小编Mer*_*Fox的帖子

使用 Pyside 从主窗口打开子对话框窗口

所以我开始用 pyside 学习 Python 进行 GUI 开发,我一直在使用 QT Designer 来提高速度并将 .ui 文件转换为 .py

我目前有一个“主窗口”用户界面和一个“关于”用户界面(主窗口被设置为主窗口,关于是一个空对话框)

如何从主窗口打开关于对话框?以下代码从我的 main.py 打开主窗口

class MainWindow(QMainWindow, mainwindow.Ui_MainWindow):
def __init__(self, parent=None):
    super(MainWindow, self).__init__(parent)
    self.setupUi(self)

app = QApplication(sys.argv)
form = MainWindow()
form.show()

app.exec_()
Run Code Online (Sandbox Code Playgroud)

一切正常,它打开了主窗口。在我的主窗口中有菜单项,其中一个是“关于”选项,当用户单击它时,我希望它显示我创建的另一个对话框 ui,我该怎么做?

在 mainwindow.py(从 ui 转换而来)中有这些引用:

self.actionAbout_mailer_0_0_1 = QtGui.QAction(MainWindow)
self.actionAbout_mailer_0_0_1.setObjectName("actionAbout_mailer_0_0_1")
self.menuAbout.addAction(self.actionAbout_mailer_0_0_1)
Run Code Online (Sandbox Code Playgroud)

而 about.py(从 ui 转换而来)看起来像这样:

from PySide import QtCore, QtGui

class About_Dialog(object):
def setupUi(self, Dialog):
    Dialog.setObjectName("Dialog")
    Dialog.resize(400, 300)
    self.aboutLbl = QtGui.QLabel(Dialog)
    self.aboutLbl.setGeometry(QtCore.QRect(110, 40, 171, 16))
    self.aboutLbl.setObjectName("aboutLbl")

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

def retranslateUi(self, Dialog):
    Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
    self.aboutLbl.setText(QtGui.QApplication.translate("Dialog", …
Run Code Online (Sandbox Code Playgroud)

python qt qt-designer pyside python-2.7

4
推荐指数
1
解决办法
4984
查看次数

标签 统计

pyside ×1

python ×1

python-2.7 ×1

qt ×1

qt-designer ×1