Skip to content
Advertisement

QTextedit find() always returns False (pyside2)

I want to do some search and replace in a QTextEdit but QTextEdit.find() always returns False/finds nothing. Where is my mistake?

Here is a (very) minimal reproducible example:

JavaScript

Thx for that -.-: “This question already has an answer here: QTextEdit.find() doesn’t work in Python”

That is not true. (Maybe read the questions and answers before stating something like that and closing questions. This is the behavior why stackoverflow has such a bad reputation.): “The problem is the position of the cursor in the window. By default the search only happens forward (= from the position of the cursor onwards). But i set my cursor to the start of the document via cursor.movePosition(QTextCursor.Start)

Advertisement

Answer

I found that textedit.textCursor() creates local copy of position and it doesn’t change original position in QTextEdit.

You have to update position in QTextEdit using

JavaScript

and then find() will find first t as you expect.


JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement