0

A method to find a substring and highlight it in QTextEdit has already been proposed in stackoverflow by vicent.

This is an elegant and effective method. However as it is used:

cursor.movePosition(QtGui.QTextCursor.EndOfWord, 1)

the highlighting goes to the end of the word where the substring is detected.

I am looking for a way to define the exact number of characters. Something like this (doesn't work!):

cursor.movePosition(len(pattern), 1)

to highlight only the substring.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
servoz
  • 606
  • 9
  • 22

1 Answers1

1

Use a for-loop with QTextCursor::Right:

for _ in pattern:
    cursor.movePosition(QtGui.QTextCursor.Right, 1)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241