Results 1 to 7 of 7

Thread: QPalette won't set QLabel's Window & Foreground color

  1. #1
    Join Date
    Jan 2006
    Posts
    10

    Default QPalette won't set QLabel's Window & Foreground color

    Hi, i am using qt 4.1.0 on a window xp platform. I use the appraoch below to set the label's forefround and Window color but nothing happens. I have serch every where for clues to solve this but to no avale. I greatly appreciate any help. Thanks

    QPalette temp;
    temp.setColor(QPalette::Foreground, QColor(255, 0, 0));
    temp.setColor(QPalette::Window, QColor(0, 0, 0));

    for (int i = 0; i < iColSize; i++)
    {
    ptrLbl = new QLabel(this);
    ptrLbl->setObjectName("XXX");
    ptrLbl->setGeometry( X,X,X,X );
    ptrLbl->setFrameShape( QFrame::StyledPanel );
    ptrLbl->setAlignment( int( Qt::AlignLeft ) );
    ptrLbl->setMouseTracking(true);

    ptrLbl->setPalette(temp);
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QPalette won't set QLabel's Window & Foreground color

    at the end you must show your label
    Qt Code:
    1. ptrLbl->show();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    10

    Default Re: QPalette won't set QLabel's Window & Foreground color

    it didn't work. Just found out that it must be something more.

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

    Default Re: QPalette won't set QLabel's Window & Foreground color

    Does it work when you use different style?
    sh Code:
    1. C:\...> app.exe -style plastique
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette won't set QLabel's Window & Foreground color

    Two problems:
    1) QPalette::Foreground is deprecated, use WindowText instead.
    2) A label does not have a background in Qt4.1, only the text is drawn. To fill the background automatically you can use setAutoFillBackground(true) on your labels.

    Qt Code:
    1. QPalette temp;
    2. temp.setColor(QPalette::WindowText, QColor(255, 0, 0));
    3. temp.setColor(QPalette::Window, QColor(0, 0, 0));
    4.  
    5. for (int i = 0; i < iColSize; i++)
    6. {
    7. ptrLbl = new QLabel(this);
    8. ptrLbl->setObjectName("XXX");
    9. ptrLbl->setAutoFillBackground( true );
    10. ptrLbl->setGeometry( X,X,X,X );
    11. ptrLbl->setFrameShape( QFrame::StyledPanel );
    12. ptrLbl->setAlignment( int( Qt::AlignLeft ) );
    13. ptrLbl->setMouseTracking(true);
    14.  
    15. ptrLbl->setPalette(temp);
    16. }
    To copy to clipboard, switch view to plain text mode 

    Hope this helps.

  6. #6
    Join Date
    Jan 2006
    Posts
    10

    Default Re: QPalette won't set QLabel's Window & Foreground color

    Thanks orb9 for your help. I have yet to try your suggestion. I'll let you know when i have. It is a busy week for me in the office. Again thank you so much. Appreciate your help.

  7. #7
    Join Date
    Jan 2006
    Posts
    10

    Default Re: QPalette won't set QLabel's Window & Foreground color

    orb9.....i tried your suggestion and it didn't worked out as we hoped. Thanks for your help. You have beeen very helpful.

Similar Threads

  1. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23: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.