[Solved] Background-color in stylesheet not taking effect

  • I have a Designer UI window called MonitorWindow. Here's a little bit of the monitorwindow.h file:
    class MonitorWindow : public QWidget

    explicit MonitorWindow(QWidget *parent = 0);
    Ui::MonitorWindow *ui;
    Here's part of the constructor from monitorwindow.cpp where I initialize the stylesheet:
    MonitorWindow::MonitorWindow(QWidget *parent) :
    ui(new Ui::MonitorWindow)
    setStyleSheet("QWidget { background-color: #FF0000; }");
    When I run the code, the background of the UI form certainly isn't red. Why isn't the background changing to FF0000? A QStackedWidget class is instantiating the MonitorWindow QWidget - will this make a difference?

  • Try this:
    @ setAttribute(Qt::WA_StyledBackground, true);
    setStyleSheet("QWidget { background-color: #FF0000; }");@

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.