Hi,

In my texteditor application I'd like to highlight all occurrence of a word under cursor. The problem is that it works for all lines except highlighted line.
Qt Code:
  1. void CodeEditor::test()
  2. {
  3. highlightCurrentLine(); //function based on CodeEditor example
  4. highlightCurrentWord("bar");
  5. }
  6.  
  7. void CodeEditor::highlightCurrentWord(QString curWord)
  8. {
  9. fmt.setBackground(Qt::red);
  10. fmt.setForeground(Qt::black);
  11. //...
  12. QTextCursor cursor = QTextCursor(block);
  13. cursor.select(QTextCursor::WordUnderCursor);
  14. //...
  15. cursor.setPosition(begin, QTextCursor::MoveAnchor);
  16. cursor.setPosition(end, QTextCursor::KeepAnchor);
  17. cursor.mergeCharFormat(fmt); //I did try also cursor.setCharFormat(fmt);
  18. //...
To copy to clipboard, switch view to plain text mode 

So for example if I have three lines

foo xyz bar

bar edddd

abc bar

let's say line 1 is cursor current line and therefore is highlighted. I want to highlight 'bar' word it will be highlighted in lines 2, 3 but not in line 1 cause of line highlight present.

Anyone know how to solve this issue ? somehow merge formating ?

Thanks in advance!