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. QPalette is useless after QSS
Qt 6.11 is out! See what's new in the release blog

QPalette is useless after QSS

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 289 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote last edited by
    #1
    ui->centralWidget->setStyleSheet("border:none;");
    
    QColor color = QColorDialog::getColor(color, this);
    QPalette palette = ui->centralWidget->palette();
    palette.setColor(ui->centralWidget->backgroundRole(), color);
    ui->centralWidget->setPalette(palette);
    

    https://github.com/sonichy

    Pl45m4P 1 Reply Last reply
    0
    • sonichyS sonichy
      ui->centralWidget->setStyleSheet("border:none;");
      
      QColor color = QColorDialog::getColor(color, this);
      QPalette palette = ui->centralWidget->palette();
      palette.setColor(ui->centralWidget->backgroundRole(), color);
      ui->centralWidget->setPalette(palette);
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by Pl45m4
      #2

      @sonichy

      As far as I know, the QSS overwrites palette settings, even if you modify the palette and re-apply it again.
      When you need the new palette with color from ColorDialog and "border: none" try to set the stylesheet after palette.

      ui->centralWidget->setStyleSheet(""); // delete stylesheet
      
      QColor color = QColorDialog::getColor(color, this);
      QPalette palette = ui->centralWidget->palette();
      palette.setColor(ui->centralWidget->backgroundRole(), color);
      ui->centralWidget->setPalette(palette);
      
      ui->centralWidget->setStyleSheet("border:none;"); // modify new palette with stylesheet
      

      This works?!

      Or what do you mean by "useless"?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      sonichyS 1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote last edited by Chris Kawa
        #3

        QSS does not overwrite palette. It just applies a different style (QStylesheetStyle), that may or may not use the palette colors. If you set a stylesheet that hardcodes a color then it won't use the palette.

        Still, you can use palette colors in QSS if you want, e.g.

        someWidget->setStyleSheet("background-color: palette(background);");
        
        Pl45m4P 1 Reply Last reply
        3
        • Pl45m4P Pl45m4

          @sonichy

          As far as I know, the QSS overwrites palette settings, even if you modify the palette and re-apply it again.
          When you need the new palette with color from ColorDialog and "border: none" try to set the stylesheet after palette.

          ui->centralWidget->setStyleSheet(""); // delete stylesheet
          
          QColor color = QColorDialog::getColor(color, this);
          QPalette palette = ui->centralWidget->palette();
          palette.setColor(ui->centralWidget->backgroundRole(), color);
          ui->centralWidget->setPalette(palette);
          
          ui->centralWidget->setStyleSheet("border:none;"); // modify new palette with stylesheet
          

          This works?!

          Or what do you mean by "useless"?

          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote last edited by
          #4

          @Pl45m4 It do not work !
          https://gitlink.org.cn/sonichy/HTYImageViewer

          https://github.com/sonichy

          1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            QSS does not overwrite palette. It just applies a different style (QStylesheetStyle), that may or may not use the palette colors. If you set a stylesheet that hardcodes a color then it won't use the palette.

            Still, you can use palette colors in QSS if you want, e.g.

            someWidget->setStyleSheet("background-color: palette(background);");
            
            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote last edited by
            #5

            @Chris-Kawa said in QPalette is useless after QSS:

            QSS does not overwrite palette.

            Of course it does not change the current palette itself. But it changes the current appearance of the active palette by adding modifications to it. If that makes sense. This is what I mean above.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            1

            • Login

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