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. Is there a way I can add extra ColorRole to QPalette?

Is there a way I can add extra ColorRole to QPalette?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k Views 2 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    The QPalette::ColorRole enum defines 20 color roles. I want to add 4 new color roles to this enum so that I can assign separate background colors to widgets based on their level in my GUI. Is there any way this can be achieved? Can I do it by subclassing QPalette?

    The best solution for me till now is to setAutoFillBackground(true) and then change the background role, e.g. setBackgroundRole(QPalette::Link) where I have already set QPalette::Link to my desired color. But this method interferes with the normal use of QPalette::Link color role which I would like to avoid. Any suggestions? I don't want to use StyleSheets, it is messy.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You might be better off creating a proxy style to handle your custom colors.

      You need to do custom stuff anyway since Qt would not know about your custom QPalette color.

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

      CJhaC 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You might be better off creating a proxy style to handle your custom colors.

        You need to do custom stuff anyway since Qt would not know about your custom QPalette color.

        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on last edited by CJha
        #3

        @SGaist Thanks! But doing a custom style seems like too much work for too little change. I guess I will just use QPalette::Link and a few others to implement my colours. I hope it won't create any problems.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You do not a full custom QStyle, there's QProxyStyle for lighter weight customization.

          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
          1

          • Login

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