Kill Console
Kill Console

Reputation: 2023

How to get the changes immediately in textEdit widget in PyQt?

I want to make a regex tester. There are two textEdit widgets in the dialog. The first one is used to input the regex, the second one is used to input the data. If the regex can match the data in second textEdit, the matched string will be highlighted.

But I do not want to add any buttons in the dialog, so how can I get the changes immediately in regex textEdit widget, so I can highlight the matched data in second one?

Upvotes: 2

Views: 3278

Answers (2)

Hannes Ovrén
Hannes Ovrén

Reputation: 21851

You should be able to catch this using the textChanged signal.

Just connect that signal to a callback, and you are done:

def my_callback(widget, *args):
    # Do something with the widget

textedit_widget.textChanged.connect(my_callback)

Upvotes: 7

Shf
Shf

Reputation: 3493

Look at QLineEdit's signals textChanged ( const QString & text ) or, for example, returnPressed (). You can simply connect this signals from either of this two QLineEdits to slot, where you process matching and do the highlighting

Upvotes: 0

Related Questions