January 12, 2011

calberto calberto
Lab Rat
18 posts

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.

7 replies

January 12, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

you could try to acheive that by styling.

QComboBox::setStyleSheet [doc.qt.nokia.com]

with the sub control drop down [doc.qt.nokia.com] size set to 0.

 Signature 

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

January 12, 2011

Mohsen Mohsen
Robot Herder
725 posts

well documented :)

Gerolf wrote:
you could try to acheive that by styling.

QComboBox::setStyleSheet [doc.qt.nokia.com]

with the sub control drop down [doc.qt.nokia.com] size set to 0.

 Signature 

www.madagon.com

January 12, 2011

Volker Volker
Robot Herder
5428 posts

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

January 12, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts
Volker wrote:
You could reimplement “QComboBox::showPopup() :“http://doc.qt.nokia.com/stable/qcombobox.html#showPopup to do nothing.

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

 Signature 

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

January 13, 2011

calberto calberto
Lab Rat
18 posts

Gerolf wrote:
you could try to acheive that by styling.

QComboBox::setStyleSheet [doc.qt.nokia.com]

with the sub control drop down [doc.qt.nokia.com] size set to 0.

Thanks, I hide the drop-down control with:

  1. ::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:
  1. 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).

January 13, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

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

 Signature 

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

January 13, 2011

calberto calberto
Lab Rat
18 posts

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.

 
  ‹‹ Spacers and Layouts      Qss and bottom-border ››

You must log in to post a reply. Not a member yet? Register here!