Results 1 to 4 of 4

Thread: coloring the QString

  1. #1
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default coloring the QString

    Qt Code:
    1. QString text("<FONT COLOR=red>%1</FONT>");
    2. text.arg(strMat);
    3. QDomNode text_node
    4. text_node.setNodeValue(text);
    To copy to clipboard, switch view to plain text mode 

    i have the above code . what i want is text color shall be red and that text value shall be decided during the run time .

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: coloring the QString

    what i want is text color shall be red and that text value shall be decided during the run time .
    You should make an effort to describe the problem and analyse what each step of your code is doing (or not doing). Do this quite often leads to seeing your own mistake.

    You are discarding the result of the function call at line 2. The value of 'text' at line 4 is the same as line 1.

  3. The following user says thank you to ChrisW67 for this useful post:

    riarioriu3 (28th September 2012)

  4. #3
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: coloring the QString

    QString pmsg;
    pmsg = tr("<font color = red >Hello qt ..!!.\n"" </font size = 11 >");
    ui->label->setText(pmsg);

    above code will print the text in red colour

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: coloring the QString

    above code will print the text in red colour
    Yes. So?

    If you are going to use HTML fragments to do rich text at least try to feed Qt valid HTML. What do you expect the attribute on the element end tag are going to do?
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. QLinearGradient Coloring
    By WSQtProgrammer in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2012, 17:59
  2. Coloring each character of a QString with QSyntaxHighlighter
    By Stanfillirenfro in forum Qt Programming
    Replies: 4
    Last Post: 7th June 2012, 17:42
  3. Coloring Circle
    By Jeneo W. in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2010, 04:39
  4. Problem with row coloring in qtableview
    By Tiansen in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2010, 18:13
  5. Coloring a QTableview column
    By Potch in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2009, 23:18

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