Results 1 to 4 of 4

Thread: Highlight a line of a TextEdit

  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Highlight a line of a TextEdit

    I know how to select (again not too hard) but need to know how to change the color of a single line from a QTextEdit?

    Example:
    Line 1
    Line 2
    Line 3 highlighted
    Line 4
    Line 5 highlighted

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Highlight a line of a TextEdit

    To select, use QTextCursor like this (you can move the cursor before selecting with setPosition ( QTextCursor: KeepAnchor)):
    Code:
     QTextCursor textEdit = cursor -> TextCursor ();
     cursor. setPosition (n QTextCursor: KeepAnchor);
     textEdit -> setTextCursor (cursor);

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Highlight a line of a TextEdit

    The QTextCursor class offers an API to access and modify QTextDocuments, TextEdit does indeed support the desired display of text/color/background combination and even that can be further edited.
    Code:
    // Style Sheet
    textEdit->setStyleSheet("color: black; background-color: white; selection-color: white; selection-background-color: black;");

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Highlight a line of a TextEdit

    Code:
     QTextCursor textEdit = cursor -> TextCursor () / / It gets a QTextCursor the text box
     cursor. setPosition (n QTextCursor: KeepAnchor) / / The location n is the position recovered by indexOf ( "test") on textEdit-> toPlainText ()
     textEdit -> setTextCursor (cursor) / / Used in this case to ensure that the selection is visible to the user

Similar Threads

  1. OS X Lion TextEdit only for editing TXT files.
    By -Deven- in forum Operating Systems
    Replies: 3
    Last Post: 14-10-2011, 10:34 PM
  2. How do you control the margins in TextEdit?
    By Beryl in forum Windows Software
    Replies: 6
    Last Post: 24-05-2010, 09:26 AM
  3. How to use Substitution function in TextEdit
    By Jabeena in forum Windows Software
    Replies: 5
    Last Post: 17-02-2010, 09:07 AM
  4. How to implement Textedit in MAC
    By DeMario in forum Windows Software
    Replies: 5
    Last Post: 26-01-2010, 01:03 AM
  5. How to highlight an active line ?
    By Basaam in forum Windows Software
    Replies: 4
    Last Post: 28-07-2009, 06:26 PM

Tags for this Thread

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
  •  
Page generated in 1,714,138,593.29805 seconds with 17 queries