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. QComboBox palette not working
Forum Updated to NodeBB v4.3 + New Features

QComboBox palette not working

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 3.0k 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.
  • EngelardE Engelard

    @SGaist said in QComboBox palette not working:

    What version of Qt are you using ?

    alt text

    On what platform ?

    Windows 10 Education

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #4

    @Engelard
    Hi
    That is the Qt version Creator was build with.
    The Qt version used to make programs can be very
    different. (and you can have multiple version installed)

    you can look in Projects
    alt text

    1 Reply Last reply
    1
    • SGaistS SGaist

      Hi,

      What version of Qt are you using ?
      On what platform ?

      Note that the platform is allowed to ignore values of the palette so it might be what is happening.

      EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by
      #5

      @SGaist said in QComboBox palette not working:

      Note that the platform is allowed to ignore values of the palette so it might be what is happening.

      Definitely not. Since i mentioned at the beginning that palette of textColors are applied to my ComboBoxes, so that is not igrnoring.

      mrjjM 1 Reply Last reply
      0
      • EngelardE Engelard

        @SGaist said in QComboBox palette not working:

        Note that the platform is allowed to ignore values of the palette so it might be what is happening.

        Definitely not. Since i mentioned at the beginning that palette of textColors are applied to my ComboBoxes, so that is not igrnoring.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @Engelard
        Hi
        Some platforms QStyle might not use ( as in ignore) some of the roles.
        Some roles that worked on linux had no effect in Windows in my app.
        http://doc.qt.io/qt-5/style-reference.html

        Also, the Qcombobox is actually a view and uses the models role hints which
        might not use palette that much for "items"
        https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.html

        EngelardE 1 Reply Last reply
        2
        • mrjjM mrjj

          @Engelard
          Hi
          Some platforms QStyle might not use ( as in ignore) some of the roles.
          Some roles that worked on linux had no effect in Windows in my app.
          http://doc.qt.io/qt-5/style-reference.html

          Also, the Qcombobox is actually a view and uses the models role hints which
          might not use palette that much for "items"
          https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.html

          EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by
          #7

          @mrjj Frankly i changed all to styleSheets, not such handy, more complex code but working more or less...

          mrjjM 1 Reply Last reply
          0
          • EngelardE Engelard

            @mrjj Frankly i changed all to styleSheets, not such handy, more complex code but working more or less...

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @Engelard
            ok :)
            Im not sure what you want to color, but stylesheet works fine as long
            one not trying to combine with models roles :)

            EngelardE 1 Reply Last reply
            1
            • mrjjM mrjj

              @Engelard
              ok :)
              Im not sure what you want to color, but stylesheet works fine as long
              one not trying to combine with models roles :)

              EngelardE Offline
              EngelardE Offline
              Engelard
              wrote on last edited by
              #9

              @mrjj said in QComboBox palette not working:

              Im not sure what you want to color,

              simple BG-color, with palette it would be 2 lines of code, with stylesheet it 6(alot of conversons to each color from QCOlor, then it convert to string, lots of extrawork).

              mrjjM 1 Reply Last reply
              0
              • EngelardE Engelard

                @mrjj said in QComboBox palette not working:

                Im not sure what you want to color,

                simple BG-color, with palette it would be 2 lines of code, with stylesheet it 6(alot of conversons to each color from QCOlor, then it convert to string, lots of extrawork).

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @Engelard
                You can also do
                ui->comboBox->setItemData( 0, QColor( Qt::black ), Qt::BackgroundRole );
                ui->comboBox->setItemData( 1, QColor( Qt::red ), Qt::BackgroundRole );
                since its uses an (internal) model. and is basically a view like Listview etc.

                EngelardE 1 Reply Last reply
                1
                • mrjjM mrjj

                  @Engelard
                  You can also do
                  ui->comboBox->setItemData( 0, QColor( Qt::black ), Qt::BackgroundRole );
                  ui->comboBox->setItemData( 1, QColor( Qt::red ), Qt::BackgroundRole );
                  since its uses an (internal) model. and is basically a view like Listview etc.

                  EngelardE Offline
                  EngelardE Offline
                  Engelard
                  wrote on last edited by Engelard
                  #11

                  @mrjj said in QComboBox palette not working:

                  @Engelard
                  You can also do
                  ui->comboBox->setItemData( 0, QColor( Qt::black ), Qt::BackgroundRole );
                  ui->comboBox->setItemData( 1, QColor( Qt::red ), Qt::BackgroundRole );

                  Hey, that's pretty good!

                  But it applied only for items inside(which great, will use in future maybe), i still can't find something like ->setData(); so it would be applied for comboBox container it'self.

                  mrjjM 1 Reply Last reply
                  0
                  • EngelardE Engelard

                    @mrjj said in QComboBox palette not working:

                    @Engelard
                    You can also do
                    ui->comboBox->setItemData( 0, QColor( Qt::black ), Qt::BackgroundRole );
                    ui->comboBox->setItemData( 1, QColor( Qt::red ), Qt::BackgroundRole );

                    Hey, that's pretty good!

                    But it applied only for items inside(which great, will use in future maybe), i still can't find something like ->setData(); so it would be applied for comboBox container it'self.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @Engelard
                    well the roles in the model is only use for items and not for the view
                    http://doc.qt.io/qt-5/qcombobox.html#view

                    but it tried your code and it did work for me ??

                    alt text

                    EngelardE 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Engelard
                      well the roles in the model is only use for items and not for the view
                      http://doc.qt.io/qt-5/qcombobox.html#view

                      but it tried your code and it did work for me ??

                      alt text

                      EngelardE Offline
                      EngelardE Offline
                      Engelard
                      wrote on last edited by
                      #13

                      @mrjj said in QComboBox palette not working:

                      but it tried your code and it did work for me ??

                      sorry i don't get that part.

                      mrjjM 1 Reply Last reply
                      0
                      • EngelardE Engelard

                        @mrjj said in QComboBox palette not working:

                        but it tried your code and it did work for me ??

                        sorry i don't get that part.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @Engelard
                        Hi

                        QPalette oriPal;  //at the .h file
                        oriPal = cbBox->palette();
                        oriPal.setColor(QPalette::Base, Qt::red);
                        cbBox->setPalette(oriPal);
                        

                        did color it red as picture showed.
                        so it did use QPalette::Base ( Qt 5.11, windows)

                        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