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. Changine Palette to Dark, doesn´t change everything.
QtWS25 Last Chance

Changine Palette to Dark, doesn´t change everything.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 2.2k 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.
  • BDC_PatrickB Offline
    BDC_PatrickB Offline
    BDC_Patrick
    wrote on last edited by BDC_Patrick
    #1

    Hi there..
    I managed to change my Color Palette at runtime, with simply changing the QPalette.'

    But i think, there are some Widgets Missing in the ColorRoles. For example:
    Menubar, Toolbar, Tabmenu, scrollArea, Scrollbars...and a few more

    Cause those Widget won´t get color changed, like the rest.

    These are the Palettes:

        QPalette darkPalette;
        QPalette lightPalette = QStyleFactory::create("fusion")->standardPalette();
        darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
        darkPalette.setColor(QPalette::WindowText, Qt::white);
        darkPalette.setColor(QPalette::Disabled, QPalette::WindowText,QColor(127, 127, 127));
        darkPalette.setColor(QPalette::Base, QColor(42, 42, 42));
        darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
        darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
        darkPalette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
        darkPalette.setColor(QPalette::Text, Qt::white);
        darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
        darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35));
        darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20));
        darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
        darkPalette.setColor(QPalette::ButtonText, Qt::white);
        darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText,QColor(127, 127, 127));
        darkPalette.setColor(QPalette::BrightText, Qt::red);
        darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
        darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
        darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
        darkPalette.setColor(QPalette::HighlightedText, Qt::white);
        darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText,QColor(127, 127, 127));
    

    Is there something missing?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #5

      Qt is using platform specific QStyles. These try to mimic the normal appearances of the according OSes. Unfortunately, this means that not everything uses QPalette entries. I guess what would work best is the "Fusion" style. However, it does not look normal on Windows and Mac. You could tweak styles using a QProxyStyle to just change certain things without reimplementing the whole style.

      That being said: We use tweaked QPalette plus stylesheets for the rest. This works great.

      @BDC_Patrick said in Changine Palette to Dark, doesn´t change everything.:

      ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");

      Does your Toolbar have a property toolBar? Normally, you would set the stylesheet for QToolBar:

      ui->toolBar->setStyleSheet("QToolBar {...}");
      
      BDC_PatrickB 1 Reply Last reply
      2
      • S Offline
        S Offline
        stryga42
        wrote on last edited by
        #2

        My personal experience (definitely not a "canonical answer") is that Qt widgets better support CSS like modification than palette tweaking. See e.g. https://doc.qt.io/qt-5/stylesheet-reference.html as a starting point.

        1 Reply Last reply
        0
        • BDC_PatrickB Offline
          BDC_PatrickB Offline
          BDC_Patrick
          wrote on last edited by BDC_Patrick
          #3

          Thanks.. but.. how?

          F.e.:

                  ui->toolBar->setPalette(darkPalette);
                  ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");
          

          i added the dark Palette to my Toolbar, so it changes dark, too.
          Now i want to apply a gradient effect... Same way, i do recoloring of the background colors of other widgets..
          But for toolbar, it is not working..
          And it doesn´t matter if i use
          background or backgound-color, toolbar or QToolBar.. or if i use #hex color or rgba..
          One time, it doesn´t affect anything.. second time.. it shows only black..
          The toolbar won´t get a gradient T_T

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

            Not exactly what you ask for but you could try a border-image https://doc.qt.io/qt-5/stylesheet-reference.html#border-image

            ui->mainToolBar->setStyleSheet("border-image: url(:/ic/res/GradientImage.JPG)");
            

            worked reasonably well on my system (ubuntu, Qt 5.7 - I know, ages old)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #5

              Qt is using platform specific QStyles. These try to mimic the normal appearances of the according OSes. Unfortunately, this means that not everything uses QPalette entries. I guess what would work best is the "Fusion" style. However, it does not look normal on Windows and Mac. You could tweak styles using a QProxyStyle to just change certain things without reimplementing the whole style.

              That being said: We use tweaked QPalette plus stylesheets for the rest. This works great.

              @BDC_Patrick said in Changine Palette to Dark, doesn´t change everything.:

              ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");

              Does your Toolbar have a property toolBar? Normally, you would set the stylesheet for QToolBar:

              ui->toolBar->setStyleSheet("QToolBar {...}");
              
              BDC_PatrickB 1 Reply Last reply
              2
              • S SimonSchroeder

                Qt is using platform specific QStyles. These try to mimic the normal appearances of the according OSes. Unfortunately, this means that not everything uses QPalette entries. I guess what would work best is the "Fusion" style. However, it does not look normal on Windows and Mac. You could tweak styles using a QProxyStyle to just change certain things without reimplementing the whole style.

                That being said: We use tweaked QPalette plus stylesheets for the rest. This works great.

                @BDC_Patrick said in Changine Palette to Dark, doesn´t change everything.:

                ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");

                Does your Toolbar have a property toolBar? Normally, you would set the stylesheet for QToolBar:

                ui->toolBar->setStyleSheet("QToolBar {...}");
                
                BDC_PatrickB Offline
                BDC_PatrickB Offline
                BDC_Patrick
                wrote on last edited by
                #6

                @SimonSchroeder Thanks..
                I think I'll give myself a full qss push..

                Pl45m4P 1 Reply Last reply
                0
                • BDC_PatrickB BDC_Patrick

                  @SimonSchroeder Thanks..
                  I think I'll give myself a full qss push..

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #7

                  @BDC_Patrick

                  If your QToolBar's name is toolBar and you want to change only this specific toolbar, then it would be

                  ("QToolBar#toolBar { . . . } ");


                  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
                  0

                  • Login

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