Results 1 to 2 of 2

Thread: cannot change QStatusBar background color

  1. #1
    Join Date
    Nov 2011
    Location
    Karlsruhe, Germany
    Posts
    57
    Thanks
    10
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default cannot change QStatusBar background color

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QMainWindow window;
    6. QStatusBar statusBar;
    7. QPalette palette;
    8.  
    9. window.setWindowTitle("QMainWindow with Colored QStatusBar");
    10. window.setFixedSize(300,100);
    11. window.setStatusBar(&statusBar);
    12.  
    13. palette.setColor(QPalette::Background, Qt::red);
    14.  
    15. statusBar.setPalette(palette);
    16. statusBar.showMessage("Red QStatusBar");
    17. window.show();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    i used the example code but the background color remained as the default one.
    any idea?

    4.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: cannot change QStatusBar background color

    Usually the code to change a widget's background color looks like this
    Qt Code:
    1. QPalette palette = widget->palette(); // get current palette
    2.  
    3. palette.setColor(QPalette::Background, color); // modify palette
    4.  
    5. widget->setPalette(palette); // apply modified palette
    6.  
    7. widget->setAutoFillBackground(true); // tell widget to fill its background itself
    To copy to clipboard, switch view to plain text mode 

    Btw, you don't have to create a QStatusBar, QMainWindow::statusBar() will do that for you and always return the same instance

    Cheers,
    _

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

    cic (19th November 2013)

Similar Threads

  1. cannot change QLCDNumber background color
    By saman_artorious in forum Qt Programming
    Replies: 2
    Last Post: 13th March 2013, 16:04
  2. How to change the color of background of QMainwindow?
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 5th July 2012, 23:56
  3. Replies: 0
    Last Post: 19th November 2010, 09:52
  4. Replies: 1
    Last Post: 17th August 2010, 16:17
  5. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14

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.