Reputation: 1113
How can I connect to a function on close of QTextEdit widget Window?
My Code:
self.textBox = QtGui.QTextEdit()
self.textBox.setWindowTitle('Editor')
self.textBox.setGeometry(100, 100, 1000, 500)
self.textBox.show()
self.textBox.???.connect(self.someFunc) #????
If I do
self.textBox.close().connect(self.someFunc)
It closes immediately and says
AttributeError: 'bool' object has no attribute 'connect'
If I do
self.textBox.closeEvent(self.someFunc)
It says
TypeError: QTextEdit.closeEvent(self.someFunc): argument 1 has unexpected type 'method'
How can I solve this?
Upvotes: 1
Views: 964
Reputation: 243887
It is not the most elegant way but it works, the other way is to inherit from QTextEdit and overwrite the closeEvent method by issuing a signal.
Use:
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")
Upvotes: 1