在 PyQt 中关闭 QTextEdit 时连接到 Method/Function

Connect to a Method/Function on close of QTextEdit in PyQt

如何在关闭 QTextEdit 小部件时连接到函数 Window?

我的代码:

self.textBox = QtGui.QTextEdit()
self.textBox.setWindowTitle('Editor')
self.textBox.setGeometry(100, 100, 1000, 500)
self.textBox.show()
self.textBox.???.connect(self.someFunc)   #????

如果我这样做

self.textBox.close().connect(self.someFunc)

它立即关闭并显示

AttributeError: 'bool' object has no attribute 'connect'

如果我这样做

self.textBox.closeEvent(self.someFunc)

它说

TypeError: QTextEdit.closeEvent(self.someFunc): argument 1 has unexpected type 'method'

我该如何解决这个问题?

这不是最优雅的方式,但它有效,另一种方式是继承QTextEdit并通过发出信号覆盖closeEvent方法。

使用:

    self.textBox = QTextEdit()
    self.textBox.setWindowTitle('Editor')
    self.textBox.setGeometry(100, 100, 1000, 500)
    self.textBox.show()
    self.textBox.closeEvent = self.function

def function(self, e):
    print("test")