Load QDialog directly from UI-File?

空扰寡人 提交于 2019-12-05 14:39:32

Your dialog class should be defined in exactly the same way as your main-window class. I obviously can't test it myself, but the script should look like this:

import sys
from PyQt4 import uic, QtGui, QtCore

main_dialog = uic.loadUiType("GUI.ui")[0]    
TestQDialog = uic.loadUiType("Dialog.ui")[0]

class QDialogClass(QtGui.QDialog, TestQDialog):
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)

class MyWindowClass(QtGui.QMainWindow, main_dialog):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.btn_close.clicked.connect(self.dialog)

    def dialog(self):
        dialog = QDialogClass()
        dialog.exec_()

def main():
    app = QtGui.QApplication(sys.argv)
    myWindow = MyWindowClass()
    myWindow.show()
    app.exec_()

if __name__ == "__main__":  
    main()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!