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: How hide the drop-down subcontrol?
Qt 6.11 is out! See what's new in the release blog

QComboBox: How hide the drop-down subcontrol?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 16.2k Views 1 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.
  • C Offline
    C Offline
    calberto
    wrote on last edited by
    #1

    There is a way to hide the drop-down subcontrol of a QComboBox?
    I know it could look a non-sense to do that, but I need a read-only, simple control to display the symbolic value of an enumerator. (the QComboBox is feed with the Qt metatype information). The control is created with the designer and its name is used to attach the control to the enumerator to be displayed. I could use another control, such as QLabel, but I also use the control type of the control to determine the type of visualization I want (that is: QComboBox -> symbolic emum).
    So far, to make it read-only, I disable it.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      you could try to acheive that by styling.

      "QComboBox::setStyleSheet":http://doc.qt.nokia.com/latest/qwidget.html#styleSheet-prop

      with the sub control "drop down":http://doc.qt.nokia.com/latest/stylesheet-examples.html#customizing-qcombobox size set to 0.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mohsen
        wrote on last edited by
        #3

        well documented :)

        [quote author="Gerolf" date="1294858069"]you could try to acheive that by styling.

        "QComboBox::setStyleSheet":http://doc.qt.nokia.com/latest/qwidget.html#styleSheet-prop

        with the sub control "drop down":http://doc.qt.nokia.com/latest/stylesheet-examples.html#customizing-qcombobox size set to 0.

        [/quote]

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          You could reimplement "QComboBox::showPopup() :"http://doc.qt.nokia.com/stable/qcombobox.html#showPopup to do nothing.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            [quote author="Volker" date="1294866251"]You could reimplement "QComboBox::showPopup() :"http://doc.qt.nokia.com/stable/qcombobox.html#showPopup to do nothing.[/quote]

            THis does not hide the button, it just disables the popup.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • C Offline
              C Offline
              calberto
              wrote on last edited by
              #6

              [quote author="Gerolf" date="1294858069"]you could try to acheive that by styling.

              "QComboBox::setStyleSheet":http://doc.qt.nokia.com/latest/qwidget.html#styleSheet-prop

              with the sub control "drop down":http://doc.qt.nokia.com/latest/stylesheet-examples.html#customizing-qcombobox size set to 0.

              [/quote]

              Thanks, I hide the drop-down control with:
              @
              ::drop-down { width: 0px; border-style: none}
              @
              It seem to me that the QComboBox keep to count the drop-down original size in the size of the control, so I also set:
              @
              padding: 2px 1px 1px 1px;
              @
              And now the control takes the minimum space required to display the values.
              I also try to reduce the padding for the not-disabled QComboBox, by setting "padding: 2px 1px 1px 1px", but I obtain a strange behaviour: when selected, the background is blue (as usual) while the text color is black. Without the padding overrides, the text color is white (Windows Xp style).

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                I know that QComboBox had some issues with colors of styles, but I don't know if and when they are fixed...

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  calberto
                  wrote on last edited by
                  #8

                  I have to admit that my knowledge of the style sheets and my comprehension of the boxed model is very poor. I tried some combination of various style customization and I have obtained odd effect. My last style sheet works more or less as I want, but unfortunately it is not portable since it renders differently depending of the GUI style. For instance, in "Plastique" style, a vertical bar is displayed in place of the drop-down subcontrol. Its position is not keep in count in the size of the control, that is it is overlapped over the content.

                  By the way, my real problem is to keep the controls as small as possible since I have a lot of controls to display in a single form. So, when the drop-down is not necessary I want to hide it.
                  I'll consider the possibility to use another type of control in the designer or promote the Combos to a custom control.

                  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