0

Suppose I have text like this in QTextEdit:

This is sample text

The word "sample" should be treated as if it was 1 single character, i.e. when I try to select it either all the characters in the word should be selected or none. Same when I navigate the document with left/right keys, the cursor should believe that the whole word is one single atomic item, i.e. if the cursor is at the end of the word, pressing left should jump to the beginning of the word and vice versa. Backspace should delete the whole item.

The best thing I could think of is to generate an image with that word on the fly and insert it in the right position, but this feels very hacky, I wonder if there is a better way of doing this?

pullo_van
  • 649
  • 6
  • 19

1 Answers1

0

I can suggest moving in following direction:

  1. Subclass from QTextEdit.
  2. Reimplement mousePressEvent() in which:
  3. Get the word under cursor.
  4. Select the word or highlight it.
Alexander Tyapkov
  • 4,837
  • 5
  • 39
  • 65
  • Thanks, I was trying to avoid any custom implementation of selection/arrow/backspace keys logic, hoping that there is something that can be done with native APIs. It's just the amount of edge cases to consider could make this approach quite difficult. – pullo_van Nov 28 '15 at 16:40