Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Background-color in stylesheet not taking effect
Qt 6.11 is out! See what's new in the release blog

[Solved] Background-color in stylesheet not taking effect

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

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

    public:
    explicit MonitorWindow(QWidget *parent = 0);
    ~MonitorWindow();
    Ui::MonitorWindow *ui;
    @
    Here's part of the constructor from monitorwindow.cpp where I initialize the stylesheet:
    @
    MonitorWindow::MonitorWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MonitorWindow)
    {
    ui->setupUi(this);
    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?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dimix
      wrote on last edited by
      #2

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

      http://physion.net

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved