Results 1 to 12 of 12

Thread: Setting text color on QLabel

Hybrid View

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

    Default Re: Setting text color on QLabel

    It is just a string, you can replace it however and whenever you want.

  2. #2
    Join Date
    Jan 2006
    Posts
    12
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Setting text color on QLabel

    Quote Originally Posted by wysota
    It is just a string, you can replace it however and whenever you want.
    Thanks!

    I'm kinda unfamiliar with that HTML style markup. How can I set the text for the label to be taken from for example QString or QTime with that kind of color color setting? How do I wrap it so that it does not show you the variables name, but what is stored in them instead?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Setting text color on QLabel

    Quote Originally Posted by Yorma
    How do I wrap it so that it does not show you the variables name, but what is stored in them instead?
    Qt Code:
    1. QString colour; // you can use also QColor
    2. QString text;
    3. // ...
    4. QString template = tr("<font color='%1'>%2</font>");
    5. somelabel->setText( template.arg( colour, text ) );
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Setting text color on QLabel

    Qt Code:
    1. QString colour; // you can use also QColor
    2. QString text;
    3. // ...
    4. QString template = tr("<font color='%1'>%2</font>");
    5. somelabel->setText( template.arg( colour, text ) );
    Don't use template it's a keyword
    Last edited by sunil.thaha; 14th January 2006 at 05:00.
    We can't solve problems by using the same kind of thinking we used when we created them

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Setting text color on QLabel

    Quote Originally Posted by sunil.thaha
    Don't use template it's a keyword
    Good point, I didn't notice that.

  6. #6
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 7 Times in 6 Posts

    Default Re: Setting text color on QLabel

    Quote Originally Posted by jacek
    Qt Code:
    1. QString colour; // you can use also QColor
    2. QString text;
    3. // ...
    4. QString fonttemplate = tr("<font color='%1'>%2</font>");
    5. somelabel->setText( fonttemplate.arg( colour, text ) );
    To copy to clipboard, switch view to plain text mode 
    Simply, but elegant!

    It's hints like these that make this forum so valuable.

    Jacke, if you are ever in Lincoln, NE then visit the Nebraska State Office Building and ask for me. I'll take you out for a steak dinner!!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Setting text color on QLabel

    Quote Originally Posted by GreyGeek
    if you are ever in Lincoln, NE then visit the Nebraska State Office Building and ask for me. I'll take you out for a steak dinner!!
    Thank you! Unfortunately I have no overseas journeys in my plans now, but we'll see what the future holds.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Replies: 2
    Last Post: 23rd July 2012, 08:42
  3. Replies: 0
    Last Post: 2nd September 2008, 12:01
  4. Position of text in a qlabel
    By jiveaxe in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2008, 13:26
  5. QTreeWidgetItem setting color for the text
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 17:22

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.