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 color change
QtWS25 Last Chance

QComboBox color change

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 4 Posters 20.4k 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.
  • A Offline
    A Offline
    Amaury
    wrote on last edited by
    #11

    Ok so if thse stylesheet don't change the text color in my combobox how can I do ? ^^

    I already tried to change the palette colors and the ui file with text editor but none of that change anything.

    The only way i found is to set the combo box as editable and then the text will appear in blue but I don't wan't that someone can edit the combobox.

    If there's any way to di it well ...

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #12

      Stylesheets are just strings.
      Nothing change in them unless u change the string and reapply with setStyleSheet.
      I think you are after
      QComboBox:editable {

      }
      or if only when "open"
      Docs says
      "the pop-up of the QComboBox is a QAbstractItemView and is styled using the descendant selector:"
      so maybe what u are after is

      QComboBoxQAbstractItemView {}
      

      When stylesheets do nothing, it often syntax error or simply not the right selector.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Amaury
        wrote on last edited by
        #13

        I'm going to check the QAbstractItemView, maybe that's what I'm looking for you're right.

        The thing I really don't understand is that my whole text and backgound is correctly set up when I open my combo box but when it's not there's a completly diffenrent setup (I can change the text font but not the color ) that's absurd ....

        Coming back to you after a quick research.

        mrjjM 1 Reply Last reply
        1
        • A Amaury

          I'm going to check the QAbstractItemView, maybe that's what I'm looking for you're right.

          The thing I really don't understand is that my whole text and backgound is correctly set up when I open my combo box but when it's not there's a completly diffenrent setup (I can change the text font but not the color ) that's absurd ....

          Coming back to you after a quick research.

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

          @Amaury
          -The thing I really don't understand is that my whole text and backgound is correctly set up when I open my combo box

          Well if you use a selector like QComboBox it will not affect other types than QComboBox so it wont affect
          the QAbstractItemView.
          If you use QWidget as selector it affects all( from same parent)
          but also buttons and stuff so its best to be exact.

          Think of it as u say:
          Color all boxes.
          And the thing combobox uses when open, is a circle so wont color it.

          So using selectors correctly makes it work much better :)
          selector can be a name, a (class) type and sub item.

          http://doc.qt.io/qt-5/stylesheet-reference.html
          This is important to understand to use stylesheets.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Amaury
            wrote on last edited by
            #15

            Correct me if I'm wrong, but what you're trying to tell me is that the content of the combo box is not the same object that the Combobox button and that I don't change the good properties though?

            Sorry I did not understand everything I am maybe wrong .

            mrjjM 1 Reply Last reply
            0
            • A Amaury

              Correct me if I'm wrong, but what you're trying to tell me is that the content of the combo box is not the same object that the Combobox button and that I don't change the good properties though?

              Sorry I did not understand everything I am maybe wrong .

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

              @Amaury
              A combox is multiple widgets.
              There is the combox it selv, an edit control sometimes and
              the dropdown area is a QAbstractItemView
              and so on.
              This goes for MOST widgets.
              http://doc.qt.io/qt-5/stylesheet-reference.html
              Look at all the differnt types for each Class.

              So yes, you cannot not just color the combo box and expect to work for all sub objects and types.
              However, using QWidget as selector will affect it all. But its too broad.
              So yes., its more complex than just think "i color the combobox" when you mean the
              view's items. Its not the same. :)

              1 Reply Last reply
              1
              • A Offline
                A Offline
                Amaury
                wrote on last edited by
                #17

                Alright i'm going to work on it, I wasn't thought that was that hard ^^ I used mostly buttons and things like that which were easier ;)

                mrjjM 1 Reply Last reply
                1
                • A Amaury

                  Alright i'm going to work on it, I wasn't thought that was that hard ^^ I used mostly buttons and things like that which were easier ;)

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

                  @Amaury !
                  Yes, test it out. once learned it make more sense.
                  For composite widgets like the combo box, its a bit more involving than for QPushButton.
                  Also know its cascading.
                  alt text

                  This is from setting "QWidget { background-color: rgb(170, 0, 127) ;}"
                  on the mainwindow..

                  1 Reply Last reply
                  1
                  • A Offline
                    A Offline
                    Amaury
                    wrote on last edited by
                    #19

                    Hi there I'm coming back to you and have to thank you I just understand how the stylesheets works now , I mean I was using the automatic parameters and was never specifiying any items like QComboBox or QPushButton.

                    I think I was stuck on that too long to notice what I was missing thank you a lot .

                    mrjjM 1 Reply Last reply
                    1
                    • A Amaury

                      Hi there I'm coming back to you and have to thank you I just understand how the stylesheets works now , I mean I was using the automatic parameters and was never specifiying any items like QComboBox or QPushButton.

                      I think I was stuck on that too long to notice what I was missing thank you a lot .

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

                      @Amaury
                      Super.
                      I assume you did notice the build in style sheet editor
                      if you right click any Widget in designer?
                      ( and choose change style sheet)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Amaury
                        wrote on last edited by
                        #21

                        I'm using Qt Creator and not designer so I don't have the change style sheet option on right cliking a widget , but I can edit the style sheet by using the properties editor.

                        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