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

955 views Asked by At

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?

1

There are 1 answers

0
eyllanesc On BEST ANSWER

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")