QComboBox: How hide the drop-down subcontrol?
-
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. -
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.
-
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]
-
You could reimplement "QComboBox::showPopup() :"http://doc.qt.nokia.com/stable/qcombobox.html#showPopup to do nothing.
-
[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.
-
[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). -
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.