Reputation: 103
I am using PyQT to create QMainWindow window that opens another window when a button is clicked. My problem is that the popup window remains displayed even if I close the main window which spawned it. This is very similar with the one posted here but written in C++ and I can only do Python. How can I implement the answer in Python? Here is my code:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class Pycryptor:
def mainGui(self):
app = QApplication(sys.argv)
#MainWindow
self.mainWin = QMainWindow()
self.mainWin.setGeometry(200,200,500,432)
self.mainWin.show()
#MenuBar
mainMenu = self.mainWin.menuBar()
mainMenu.setNativeMenuBar(False)
aboutMenu = mainMenu.addMenu('A&bout')
helpButton = QAction(QIcon(),'Help',self.mainWin)
helpButton.triggered.connect(self.helpPopup)
aboutMenu.addAction(helpButton)
sys.exit(app.exec_())
def helpPopup(self):
self.popup = HelpWindow()
self.popup.setGeometry(800,200,300,500)
self.popup.show()
class HelpWindow(QWidget):
def __init__(self):
QWidget.__init__(self)
if __name__ == '__main__':
p = Pycryptor()
p.mainGui()
Upvotes: 0
Views: 1294
Reputation: 1489
in c++ you can setParent your widget object a mainWindow object. When the parent will be destroyed he will follow all his children.
for example:
void MainWindow::on_pushButton_clicked()
{
Form *fm = new Form();
fm->setParent(this);
fm->setWindowFlags(Qt::Window);
fm->show();
}
i dont know hot to create this pyqt but you can read documentation: http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#setParent
Upvotes: 1