Results 1 to 2 of 2

Thread: QPlainTextEdit highlight word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPlainTextEdit highlight word

    Qt Code:
    1. void CodeEditor::highlightCurrentLine()
    2. {
    3. QList<QTextEdit::ExtraSelection> extraSelections;
    4.  
    5. if (!isReadOnly()) {
    6. QTextEdit::ExtraSelection selection;
    7.  
    8. QColor lineColor = QColor(Qt::yellow).lighter(160);
    9.  
    10. selection.format.setBackground(lineColor);
    11. selection.format.setProperty(QTextFormat::FullWidthSelection, true);
    12. selection.cursor = textCursor();
    13. selection.cursor.clearSelection();
    14. extraSelections.append(selection);
    15. }
    16.  
    17. // BEGIN: added
    18. QTextCursor cursor = textCursor();
    19. cursor.select(QTextCursor::WordUnderCursor);
    20. QTextEdit::ExtraSelection currentWord;
    21. QColor redColor = Qt::red;
    22. currentWord.format.setBackground(redColor);
    23. currentWord.cursor = cursor;
    24. extraSelections.append(currentWord);
    25. // END: added
    26.  
    27. setExtraSelections(extraSelections);
    28. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    ArkKup (4th March 2013)

Similar Threads

  1. Highlight of an ListView
    By Gihu in forum Qt Quick
    Replies: 1
    Last Post: 2nd July 2012, 17:13
  2. QPlainTextEdit highlight selected line
    By ArkKup in forum Qt Programming
    Replies: 0
    Last Post: 2nd November 2011, 09:45
  3. how to get the word when i highlight a word with mouse?
    By saleh.hi.62 in forum Qt Programming
    Replies: 0
    Last Post: 4th July 2010, 08:24
  4. highlight problem
    By supriyajn in forum Newbie
    Replies: 1
    Last Post: 20th May 2010, 19:00
  5. Highlight row in treeview
    By supergillis in forum Qt Programming
    Replies: 6
    Last Post: 20th November 2008, 08:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.