[英]How to trigger a method in a main Window from a dialog window in PyQt5?
[英]How to open second window from main dialog window with pyqt5 and qt designer
嗨我正在嘗試開發一個插件。 我使用了 PyQt5 設計來創建 Gui。我想知道單擊按鈕后如何啟動新的 window。
這是我使用 PyQt5 Designer 創建的界面。 這是圖片鏈接
單擊激活按鈕后,將打開發送激活密鑰對話框,如上圖所示。 單擊確定按鈕后,我需要打開一個新的 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_Dialog class
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"))
我正在使用登錄窗口調用
GisedifySupportDialog().open_login_dialog()
上面的代碼什么也不做,也沒有錯誤。 當從主 window 單擊確定按鈕時,請幫助我打開登錄 window
嘗試這個:
def open_login_dialog(self):
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.exec_()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.