PyQt: How to hide QMainWindow

给你一囗甜甜゛ 提交于 2019-11-27 22:35:59

Make the first window a parent of the second window:

class Dialog_02(QtGui.QMainWindow):
    def __init__(self, parent):
        super(Dialog_02, self).__init__(parent)
        # ensure this window gets garbage-collected when closed
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    ...    

    def closeAndReturn(self):
        self.close()
        self.parent().show()

class Dialog_01(QtGui.QMainWindow):
    ...

    def callAnotherQMainWindow(self):
        self.hide()
        self.dialog_02 = Dialog_02(self)
        self.dialog_02.show()

If you want the same dialog to be shown each time, do something like:

    def callAnotherQMainWindow(self):
        self.hide()
        if not hassattr(self, 'dialog_02'):
            self.dialog_02 = Dialog_02(self)
        self.dialog_02.show()

and hide() the child window, rather than closing it.

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