Results 1 to 4 of 4

Thread: How to hange color for different texts in plaintextedit?

  1. #1
    Join Date
    Oct 2009
    Posts
    105
    Thanked 4 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default How to hange color for different texts in plaintextedit?

    Hi All,

    I've a plain text edit in myt dialog. i want to write "XYZ " in red color and "ABC" in black color. How can i do this? i tried to set pallet. but its not working. I've attached sample code of my apllication. please help me.

    Thank you.
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2010
    Location
    Horten, Norway
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to hange color for different texts in plaintextedit?

    try this:

    Qt Code:
    1. yourTextEdit->append("<font color = red>XYZ</font>");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to hange color for different texts in plaintextedit?

    Quote Originally Posted by Stiander View Post
    Qt Code:
    1. yourTextEdit->append("<font color = red>XYZ</font>");
    To copy to clipboard, switch view to plain text mode 
    That wont work for a QPlainTextEdit. But you can set a syntaxhighlighter. See the "Syntax Highlighter Example" in the docs or direct QSyntaxHighlighter. Or you can use the the basic options of the text cursor which should be the fastest appproach. See QTextCursor and QTextCharFormat.

  4. #4
    Join Date
    Aug 2010
    Location
    Horten, Norway
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to hange color for different texts in plaintextedit?

    oh yea thats right. would work for QTextBrowser tho, and I think QTextEdit

Similar Threads

  1. Replies: 5
    Last Post: 2nd November 2012, 04:38
  2. Replies: 2
    Last Post: 13th August 2010, 11:08
  3. How to set the Text Cursor in a PlainTextEdit box?
    By Mia S. in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2010, 17:30
  4. Replies: 2
    Last Post: 13th February 2010, 19:33
  5. How to make plainTextEdit autofill to parent window?
    By kid2000 in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2009, 10:59

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.