Customizing QComboBox

3k Views Asked by At

I want to customize QComboBox. The behavior I'd like to see is a combo box where it's button (the down facing arrow), takes the whole area of the combo box when it's collapsed. I know that QComboBox is a QPushButton with a QListWidget (or some other widget). I'd like to change the QPushButton to take up the whole area. I'd like to also get rid of the area where the current selection is being displayed. Any tips will be appreciated!

Here's what I want :

enter image description here

I am able to control the width of the drop down list through QComboBox::view()->setMinimumWidth(). That way I can have a narrower combo box but a much wider drop down list. That part is done. Now I need to just have a button there.

2

There are 2 best solutions below

1
On BEST ANSWER

Setting QComboBox button, actually down arrow, can be done by a style, using down-arrow style, however, since you require the selection to be not visible, you need to take care of other settings, the width of the combobox and the drop-down should probably to exactly match your image, example style to accomplish that:

QComboBox::down-arrow {
    image: url(arrow.png); /* Set combobox button */
}

QComboBox::drop-down {
    width: 20px;  /* set the width of the drop down */
}

QComboBox {
    border: 0px;
    max-width: 20px; /* width of whole box */
}
1
On

OK, so it's very possible through style sheets. Here's what I did:

QComboBox::setStyleSheet(
QComboBox::down-arrow {
image: url(:/images/add_support_combo_box.png);
left: -50px;
top: -10px;
width: 500px;
height : 200px;}");

If you see "left" and "top" have negative values. This forces the image of the down arrow to move left and up.