Results 1 to 3 of 3

Thread: cannot change QLCDNumber background color

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default cannot change QLCDNumber background color

    here is what I do:

    Qt Code:
    1. final_angle->display(44.4);
    2. QPalette* palette = new QPalette();
    3. palette->setColor(QPalette::Background,Qt::red);
    4. final_angle->setPalette(*palette);
    To copy to clipboard, switch view to plain text mode 

    where is the problem?

  2. #2
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: cannot change QLCDNumber background color

    I put an LcdNummer Object in a gui. Then I used <obj>.setstylesheet...
    In the stylesheet I wrote background-color: red
    Works fine...

    Assuming you can: final_angle-> setStylesheet(.....);

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: cannot change QLCDNumber background color

    where is the problem?
    Qt Code:
    1. QPalette* palette = new QPalette();
    To copy to clipboard, switch view to plain text mode 

    In the first case, this is a memory leak. You should simply retrieve the existing palette from the widget:

    Qt Code:
    1. QPalette palette = final_angle->palette();
    2. palette.setColor( /* whatever */ );
    3. final_angle->setPalette( palette );
    To copy to clipboard, switch view to plain text mode 

    And if you read the QPalette documentation, you will see that QPalette::Background is an obsolete ColorRole. You should probably be using QPalette::Window or QPalette::Button; I don't know how painting in QLCDNumber is implemented, so I don't know which role it uses to paint its background.

    You do read the documentation sometimes, don't you? Or do you just simply post a question for every problem you run into?

Similar Threads

  1. QLCDNumber change the color of the number???
    By arninio123 in forum Newbie
    Replies: 1
    Last Post: 11th May 2012, 13:58
  2. Change frame background color
    By Ishmael in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 05:38
  3. how to change background color of QMenu??
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2009, 12:41
  4. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

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.