如何使用 pyqt5 和 qt 设计器从主对话框 window 打开第二个 window
How to open second window from main dialog window with pyqt5 and qt designer
嗨,我正在尝试开发一个插件。我使用 PyQt5 设计来创建 Gui.I 想知道如何在单击按钮后启动新的 window。
这是我使用 PyQt5 Designer 创建的界面。这是图片 link
单击“激活”按钮后,将打开“发送激活密钥”对话框,如上图所示。
单击确定按钮后,我需要打开一个新的 window,如图所示
这里是主要的ui_dialog.py
from .gisedify_support_dialog_login import Ui_Dialog
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'gisedify_support_dialog_base.ui'))
class GisedifySupportDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(GisedifySupportDialog, self).__init__(parent)
# Set up the user interface from Designer through FORM_CLASS.
# After self.setupUi() you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)
def open_login_dialog(self):
self.nd = Login_Dialog(self)
self.nd.show()
class Login_Dialog(QtWidgets.QDialog,Ui_Dialog):
def __init__(self, parent=None):
super(Login_Dialog, self).__init__(parent)
这是我的UI_Dialogclass
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
....
....
self.pushButton.setObjectName("pushButton")
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "Enter activation key"))
self.pushButton.setText(_translate("Dialog", "Login"))
我正在使用
调用登录window
GisedifySupportDialog().open_login_dialog()
上面的代码什么也没做,也没有错误。当从主 window
中单击确定按钮时,请帮助我打开登录 window
试试这个:
def open_login_dialog(self):
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.exec_()
嗨,我正在尝试开发一个插件。我使用 PyQt5 设计来创建 Gui.I 想知道如何在单击按钮后启动新的 window。
这是我使用 PyQt5 Designer 创建的界面。这是图片 link
单击“激活”按钮后,将打开“发送激活密钥”对话框,如上图所示。
单击确定按钮后,我需要打开一个新的 window,如图所示
这里是主要的ui_dialog.py
from .gisedify_support_dialog_login import Ui_Dialog
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'gisedify_support_dialog_base.ui'))
class GisedifySupportDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(GisedifySupportDialog, self).__init__(parent)
# Set up the user interface from Designer through FORM_CLASS.
# After self.setupUi() you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)
def open_login_dialog(self):
self.nd = Login_Dialog(self)
self.nd.show()
class Login_Dialog(QtWidgets.QDialog,Ui_Dialog):
def __init__(self, parent=None):
super(Login_Dialog, self).__init__(parent)
这是我的UI_Dialogclass
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
....
....
self.pushButton.setObjectName("pushButton")
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "Enter activation key"))
self.pushButton.setText(_translate("Dialog", "Login"))
我正在使用
调用登录windowGisedifySupportDialog().open_login_dialog()
上面的代码什么也没做,也没有错误。当从主 window
中单击确定按钮时,请帮助我打开登录 window试试这个:
def open_login_dialog(self):
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.exec_()