主窗口关闭时的信号

3

我有一个mainwindow,从它调用另一个窗口,我希望在第二个窗口关闭时执行一个槽函数。是否有任何方法可以实现这一点?

new_window = secondWindow()
new_window.show()
new_window.closed.connect(self.another function)

有没有像这样定义的信号,或者有没有其他方法可以在不关闭主窗口的情况下完成?
2个回答

4
解决方法是创建一个自定义信号,并在closeEvent方法中发出此信号:
class secondWindow(WidgetClass):
    closed = pyqtSignal()
    [...]

    def closeEvent(self, event):
        self.closed.emit()
        WidgetClass.closeEvent(self, event)

-1

简单的解决方案

QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.close)

你的代码在按钮按下时关闭了窗口,但 OP 的要求是不同的,他希望无论通过何种方式关闭窗口都能收到通知。我建议你重新阅读问题。 :-) - eyllanesc
是的,我必须同意 @eyllanesc。但感谢您的贡献。 - Nevin Baiju

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接