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. How to change QComboBox color without change the apparence

How to change QComboBox color without change the apparence

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 562 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.
  • L Offline
    L Offline
    Loann
    wrote on last edited by
    #1

    Hi ! I would like to turn a combobox in white.
    So I tried to use StyleSheet with background-color and the QPalette way.
    It works, my combobox turns white but its apparence looks like Windows XP Combobox...

    My goal is to change the color of my combobox's background while keeping its Windows 10 appearance.

    Before :
    10.PNG

    After:
    xp.PNG

    Thanks for helping !

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Loann
      wrote on last edited by Loann
      #2

      This topic is close to my case :
      https://stackoverflow.com/questions/54160285/how-to-set-background-color-of-qcombobox-button

      JonBJ 1 Reply Last reply
      0
      • L Loann

        This topic is close to my case :
        https://stackoverflow.com/questions/54160285/how-to-set-background-color-of-qcombobox-button

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Loann
        And it seems to me the accepted solution there is likely the case. If you alter any property you are in danger of losing the whole "theme".

        Note: With complex widgets such as QComboBox and QScrollBar, if one property or sub-control is customized, all the other properties or sub-controls must be customized as well.

        It looks like you have to customize everything if you want to customize the button... Then it would not be possible to change the colour without overwriting or suppressing the standard style.

        1 Reply Last reply
        0
        • Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #4

          @Loann

          Hello!

          Yes, you must change a few properties of QComboBox to make it look nice. Here is my code using only the CSS stylesheet:

          ui->comboBox->setStyleSheet("QComboBox {background-color: #FFFFFF; border: 1px solid lightgray;} QComboBox::drop-down {border: none;} "
          "QComboBox::down-arrow {image: url(:/Icons/arrow.png);} "
          "QComboBox QAbstractItemView {background-color: #FFFFFF; selection-background-color: #FFFFFF; selection-color: #000000;}");
          

          I have used a custom arrow icon similar to the default one and attached it to the program resources: QComboBox arrow

          Result:
          Custom_qcombobox_example.gif

          If you do not want the selection color, so feel free to remove this line of code: "QComboBox QAbstractItemView {background-color: #FFFFFF; selection-background-color: #FFFFFF; selection-color: #000000;}", then you will get the default selection color. Also, I would suggest you to apply your stylesheet from a resource file at program startup for better performance. You can get more details about Qt style sheets in the docs: https://doc.qt.io/qt-5/stylesheet-examples.html
          Happy coding!

          1 Reply Last reply
          2
          • L Offline
            L Offline
            Loann
            wrote on last edited by
            #5

            Thanks for your answers.
            So the best way to custom a combobox color is to edit StyleSheet Properties and manually make the combobox looks like Windows 10 apparence with a different color ?

            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