Results 1 to 4 of 4

Thread: Label text color

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Label text color

    Hi,

    I have simple question, but still can't find the 100% solution.
    I need to change label's text color, let's say to red. I am changing the palette, but the text is always black. Do I have to use stylesheets for this?

    Thanks,

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Label text color

    No, modifying the palette is fine. Can we see the code?

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Label text color

    Of course. Here's the code:
    Qt Code:
    1. PanelLabel::PanelLabel(bool visible,QString text, QColor textColor,QWidget* parent): QLabel(text,parent)
    2. {
    3. setVisible(visible);
    4. setFrameStyle(QFrame::NoFrame);
    5. setMouseTracking(true);
    6. QPalette palette;
    7. palette.setColor(QPalette::Text,textColor);
    8. setPalette(palette);
    9. }
    To copy to clipboard, switch view to plain text mode 

    The code looks fine, I suppose. Maybe the problem lays somewhere else.
    Last edited by maverick_pol; 27th February 2008 at 09:49.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

  5. The following user says thank you to jpn for this useful post:

    maverick_pol (27th February 2008)

Similar Threads

  1. Replies: 15
    Last Post: 31st January 2020, 18:25
  2. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  3. Setting a highlight text color for QTableWidgetItem
    By Hiba in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2007, 10:51
  4. Replies: 1
    Last Post: 24th October 2006, 16:40
  5. Setting text color on QLabel
    By Yorma in forum Newbie
    Replies: 11
    Last Post: 15th June 2006, 07:25

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.