1

I'm extending a QPlainTextEdit.

When I double click on a word containing a pipe char ex : {"foo"|upper|reverse} the whole text is surrounded.

I'd like to exclude the pipe char "|" from the selection and don't know what to do Is there a way to change the behavior of QTextCursor::WordUnderCursor?

I'd like that char to act the same as a space or more generally as an unselectable char.

As stated in QT docs:

Selects the word under the cursor. If the cursor is not positioned within a string of selectable characters, no text is selected.

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Christophe Eblé
  • 8,071
  • 3
  • 33
  • 32

1 Answers1

2

Currently there is no official way to change the way a text edit finds the word boundaries. See http://bugreports.qt-project.org/browse/QTBUG-150.

You may use their private API to change the behaviour of QTextEngine::atWordSeparator. This way is not recommanded by Qt. The pipe is recognized as word separator in 4.6 but not in 4.5.1 or earlier. I would suggest to update your Qt version, if that is an option. Otherwise you may give your QTextEdit a new QTextLayout with a modified QTextEngine.

rene
  • 41,474
  • 78
  • 114
  • 152
merula
  • 384
  • 2
  • 8