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 not inherited properly?
QtWS25 Last Chance

QPalette not inherited properly?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 7.9k Views
  • 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    I'm trying to build a dark version of my application.
    I chose to work only with the QPalette but I'm facing a problem :
    Usin the quick color seletion, it changes from this
    !http://imgur.com/vgWKfOg.png!
    to this
    !http://imgur.com/pxloUuo.png!

    Note the preview is absolutely broken
    !http://i.imgur.com/ihgODSf.png!

    So for instance the QSpinBox are still using the original palette when they sould inherit the one from the MainWindow.
    Now if I change the palette of each element (and set the same one as the MainWindow) I get this :
    !http://i.imgur.com/5UsYe0m.png!

    It looks better but I don't understand why, since it should look the same than when the widget inherit their palette from the MainWindow.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Skyrpex
      wrote on last edited by
      #2

      AFAIK, the default application style doesn't only use the palette to retrieve the application colors.

      You may switch the style to Fusion. That style uses only the palette, so it's fully configurable. I've even recopilated a dark version: "here is a gist.":https://gist.github.com/Skyrpex/5547015

      Feel free to contribute (it's not finished :P).

      @qApp->setStyle(QStyleFactory::create("fusion"));

      QPalette palette;
      palette.setColor(QPalette::Window, QColor(53,53,53));
      palette.setColor(QPalette::WindowText, Qt::white);
      palette.setColor(QPalette::Base, QColor(15,15,15));
      palette.setColor(QPalette::AlternateBase, QColor(53,53,53));
      palette.setColor(QPalette::ToolTipBase, Qt::white);
      palette.setColor(QPalette::ToolTipText, Qt::white);
      palette.setColor(QPalette::Text, Qt::white);
      palette.setColor(QPalette::Button, QColor(53,53,53));
      palette.setColor(QPalette::ButtonText, Qt::white);
      palette.setColor(QPalette::BrightText, Qt::red);

      palette.setColor(QPalette::Highlight, QColor(142,45,197).lighter());
      palette.setColor(QPalette::HighlightedText, Qt::black);
      qApp->setPalette(palette);@

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        Thanks for your answer.

        1. I know that some things like QPushButton cannont be style with QPalette. However QSpinBox correctly use the palette but fails to inherit it, which is my point here.

        2. Fusion. Does it work with Qt4 or is it Qt5 only?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Skyrpex
          wrote on last edited by
          #4

          I guess it's only Qt5. Not sure at all...

          Anyway, it's true that the subwidgets should inherit the palette. I've never edited the palette in Qt4 so I don't have a clue if that's a bug in your code or Qt itself.

          Regards.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            I found this:
            http://code.google.com/p/fusion-qt4/

            Will try your palette!

            Found this palette similar to yours:
            https://gist.github.com/QuantumCD/6245215

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alketi
              wrote on last edited by
              #6

              Was there ever a solution for this?

              In Qt5/Linux I'm experiencing the same behavior when dynamically switching between different palette colors, when the app is open.

              I was hoping to allow the user to switch color sets or customize colors through an in-app menu, but I see the same weirdness with certain elements not correctly re-coloring.

              If I start the app from scratch, with the same color sets, it all works fine.

              Is there a way to apply the palette dynamically?

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zeljko
                wrote on last edited by
                #7

                IMO, you cannot change palette colors just like that under ms windows, for non windows (redmond) theme, since QStyle uses native mswindows theme to paint controls (eg. under windows xp theme, you cannot change color of QPushButton, but under redmond theme you can - of course I'm talking about Qt4 here, but probably same applies to Qt5). Under X11 you can do such things and palette is applied as you want.

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #8

                  Hi Julien,

                  bq. I chose to work only with the QPalette

                  I was wondering why you want to use qpalette only? Why are stylesheets not an option?

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JulienMaille
                    wrote on last edited by
                    #9

                    Because with a QPalette you can easily set a few colors and theme the whole application (at least this is how it used to work). Stylesheet requires much more work (look at the QDarkStyle stylesheet and you'll see they had to rewrite the style of almost all widgets)

                    1 Reply Last reply
                    0
                    • EddyE Offline
                      EddyE Offline
                      Eddy
                      wrote on last edited by
                      #10

                      thanks,

                      I see your point.

                      good luck with your investigations!

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        zeljko
                        wrote on last edited by
                        #11

                        [quote author="Julien M" date="1396172572"]Because with a QPalette you can easily set a few colors and theme the whole application (at least this is how it used to work). Stylesheet requires much more work (look at the QDarkStyle stylesheet and you'll see they had to rewrite the style of almost all widgets)[/quote]

                        Indeed, but you cannot do that on all themes as I already mentioned, so stylesheet could be only option in some cases (to be clear: I prefer QPalette over stylesheets in such cases, but it does not fit in all scenarios).

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Alketi
                          wrote on last edited by
                          #12

                          Found a solution to the issue of all child widgets not coloring properly:

                          If you're using the Fusion them on Qt 5.x, which supports QPalette, the solution is to cycle through all the child widgets each time you switch the color theme.

                          @ this->setPalette(palette);

                          QList<QWidget*> widgets = this->findChildren<QWidget*>();
                          
                          foreach (QWidget* w, widgets)
                          {
                              w->setPalette(palette);
                          }
                          

                          @

                          QuantumCD posted the solution here: https://gist.github.com/QuantumCD/9863860

                          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