I have the following python code where the main window has a widget using PyQt4

import os
import sys
from PyQt4 import QtGui, QtCore, Qt


class Widget(QtGui.QLabel):
    def __init__(self):
        super(FringeFrame, self).__init__()
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.showFullScreen()

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.widget = Widget()

def main():
    app = QtGui.QApplication(sys.argv)
    mywin = MainWindow()
    mywin.show()
    sys.quit(app.exec_ ())    


if __name__ == '__main__':
    main()

the issue here is that i want widget and mywin to have their own window, it works that way, but when I close mywin, the widget is not closed with mywin. How should i do it?

有帮助吗?

解决方案

You can just override the QMainWindow's closeEvent:

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.widget = Widget()

    def closeEvent(self, event):
        self.widget.close()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top