QMainWindow 关闭时如何关闭 QDialog

How to close QDialog when QMainWindow is closed

我正在使用 PyQt,我有一个 QMainWindow,它在单击信号后生成 QDialog window。我想要的是这个 QDialog 在我关闭 QMainWindow 后简单地消失。我不能做很多文档和这个问题的 c++ 版本。下面是代码:

from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys

class App:

    def mainGui(self):
        self.mainWin = QMainWindow()
        self.mainWin.setGeometry(200,200,500,432)
        self.mainWin.show()
        mainMenu = self.mainWin.menuBar()
        mainMenu.setNativeMenuBar(False)
        aboutMenu = mainMenu.addMenu('A&bout')
        helpButton = QAction(QIcon(),'Help',self.mainWin)
        helpButton.setShortcut('F4')
        helpButton.triggered.connect(self.helpPopup)
        aboutMenu.addAction(helpButton)

    def helpPopup(self):
        self.popup = QDialog()
        self.popup.setWindowTitle('Help')
        self.popup.setGeometry(800,200,300,500)
        self.popup.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    a = App()
    a.mainGui()
    sys.exit(app.exec_())

在 Qt 中,因此也在 PyQt 中,如果父级也死了子级,那么只作为 QDialog 的父级传递给 self.mainWin:

self.popup = QDialog(self.mainWin)