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. background-color stylesheet doesn't work on centralwidget
Forum Updated to NodeBB v4.3 + New Features

background-color stylesheet doesn't work on centralwidget

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 422 Views 3 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.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hi, so when I try to change background color of centralwidget in the Design tab, it works, but when I try to do it as a command, it doesn't work.
    Here's the code I used for the stylesheet:

    ui->centralwidget->setStyleSheet("color: white;"
                                     "background-color: rgb(241, 243, 231);");
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #3

      In the Qt docs they recommend using palette for setting background color.
      I'm using this code:

          centralWidget()->setAutoFillBackground( true );
          QPalette p=centralWidget()-> palette();
          p.setColor(QPalette::Background, YOUR_COLOR);
          centralWidget()-> setPalette(p);
      
      S 2 Replies Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Do you have any other stylesheet that you apply in this widget ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #3

          In the Qt docs they recommend using palette for setting background color.
          I'm using this code:

              centralWidget()->setAutoFillBackground( true );
              QPalette p=centralWidget()-> palette();
              p.setColor(QPalette::Background, YOUR_COLOR);
              centralWidget()-> setPalette(p);
          
          S 2 Replies Last reply
          1
          • M mpergand

            In the Qt docs they recommend using palette for setting background color.
            I'm using this code:

                centralWidget()->setAutoFillBackground( true );
                QPalette p=centralWidget()-> palette();
                p.setColor(QPalette::Background, YOUR_COLOR);
                centralWidget()-> setPalette(p);
            
            S Offline
            S Offline
            Sucharek
            wrote on last edited by
            #4
            This post is deleted!
            1 Reply Last reply
            0
            • M mpergand

              In the Qt docs they recommend using palette for setting background color.
              I'm using this code:

                  centralWidget()->setAutoFillBackground( true );
                  QPalette p=centralWidget()-> palette();
                  p.setColor(QPalette::Background, YOUR_COLOR);
                  centralWidget()-> setPalette(p);
              
              S Offline
              S Offline
              Sucharek
              wrote on last edited by
              #5

              Hi @mpergand, it works perfectly, thanks.

              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