Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Problems creating dark palette

Problems creating dark palette

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 1.0k 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.
  • C Offline
    C Offline
    Chris King
    wrote on 6 Oct 2021, 00:28 last edited by
    #1

    I am using PySide2, with Qt 5.15.2 in side of Unreal Engine. I would like to create a look that matches Unreal. I have seen lots of chatter on forums about creating a dark style/theme but can't find anything directly useful.

    I thought I would try and create my own. Unfortunately there are some things I don't seem to be able to set the color for.

    I built this test case. I tried to set everything to red. I think I should get a completely red window but instead I see this:

    e9cf5e77-0a5c-4918-af11-70418d7a354c-image.png

    Here is my code:

    import sys

    from PySide2 import QtCore, QtGui, QtUiTools, QtWidgets
    from PySide2.QtGui import QPalette, QColor
    from PySide2.QtCore import Qt

    def test():

    app = QtWidgets.QApplication(sys.argv)
    
    palette = QPalette()
    
    for groupName, group in QPalette.ColorGroup.values.items():
        for roleName, role in QPalette.ColorRole.values.items():
            print(f'{groupName} - {roleName}, {int(role)}')
            if role == QPalette.ColorRole.NColorRoles:
                continue
            palette.setColor(group, role, Qt.red)
    
    app.setPalette(palette)
    
    dlg = QtWidgets.QDialog()
    button = QtWidgets.QPushButton("test", parent=dlg)
    dlg.show()
    app.exec_()
    

    test()

    Why is the button background not red? What am I doing wrong?

    Thanks,
    Chris

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 6 Oct 2021, 02:27 last edited by
      #2

      Hi @Chris-King, and welcome!

      I'm note sure why, but it seems like not all roles got set.

      The QPalette.ButtonText role seems to have been updated correctly; try to manually set the QPalette.Button role, which determines the button background.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris King
        wrote on 6 Oct 2021, 16:23 last edited by
        #3

        I tried that but it didn't work. I started out explicitly setting all the roles that I found in the documentation but there seem to be a couple of things that just don't get set that way. There is the button color and the shadow around the button that is a blue color.

        Is there something that can be overriding the palette?

        I really wish Qt had a built in dark theme or better yet a collection of themes that shipped with the source that developers could choose from.

        M 1 Reply Last reply 6 Oct 2021, 16:57
        0
        • C Chris King
          6 Oct 2021, 16:23

          I tried that but it didn't work. I started out explicitly setting all the roles that I found in the documentation but there seem to be a couple of things that just don't get set that way. There is the button color and the shadow around the button that is a blue color.

          Is there something that can be overriding the palette?

          I really wish Qt had a built in dark theme or better yet a collection of themes that shipped with the source that developers could choose from.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 6 Oct 2021, 16:57 last edited by
          #4

          @Chris-King

          Hi
          The look of Qt is drawn via QStyle and not all platform uses the same palette for the same elements.
          Also, other elements like the blue active frame might not use the palette at all.
          So it's not possible to make a complete dark style using only the palette as far as I found.

          You can get far with stylesheets.
          https://github.com/ColinDuquesnoy/QDarkStyleSheet

          • I really wish Qt had a built in dark theme or better yet a collection of themes that shipped with the source that developers could choose from.

          Well same here. On linux , a lot of themes exists and if using the right Desktop manager, you can style it to a huge degree.
          On windows, you can barely set the color as you wish and even it has a dark mode, it's not easy to reuse for a Qt app.
          It might come someday

          https://bugreports.qt.io/browse/QTBUG-72028

          J 1 Reply Last reply 7 Oct 2021, 01:13
          3
          • M mrjj
            6 Oct 2021, 16:57

            @Chris-King

            Hi
            The look of Qt is drawn via QStyle and not all platform uses the same palette for the same elements.
            Also, other elements like the blue active frame might not use the palette at all.
            So it's not possible to make a complete dark style using only the palette as far as I found.

            You can get far with stylesheets.
            https://github.com/ColinDuquesnoy/QDarkStyleSheet

            • I really wish Qt had a built in dark theme or better yet a collection of themes that shipped with the source that developers could choose from.

            Well same here. On linux , a lot of themes exists and if using the right Desktop manager, you can style it to a huge degree.
            On windows, you can barely set the color as you wish and even it has a dark mode, it's not easy to reuse for a Qt app.
            It might come someday

            https://bugreports.qt.io/browse/QTBUG-72028

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 7 Oct 2021, 01:13 last edited by
            #5

            @mrjj said in Problems creating dark palette:

            The look of Qt is drawn via QStyle and not all platform uses the same palette for the same elements.

            Ah, that's right; I forgot about that.

            If you still want to use palettes, the Fusion style has good support for palettes. Here's an example that sets a dark theme with Fusion (buttons definitely work): https://forum.qt.io/topic/25278/solved-fusion-style-how-to-set-dark-version

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            3

            3/5

            6 Oct 2021, 16:23

            • Login

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