Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QComboBox AbstractItemView::item

Is there a way I could increase the height of the items, which are listed in a QComboBox control ?

I tried following as suggested here in QTDevNet forums but with no luck

QComboBox QAbstractItemView::item {margin-top: 3px;}

I also tried this, still with no result.

QComboBox QAbstractItemView::item {min-height: 20px;}

Is it possible to achieve this at style-sheet level at all ?

like image 324
warunanc Avatar asked Nov 09 '12 12:11

warunanc


People also ask

What is a QComboBox?

A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space. A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.


2 Answers

Your style sheet seemed correct, so I tried it. It seems the problem is similar to this one on Qt centre:

QCompleter sets a custom QAbstractItemDelegate on its model and unfortunately this custom item delegate does not inherit QStyledItemDelegate but simply QItemDelegate (and then overrides the paint method to show the selected state).

If you replace the default delegate by a QStyledItemDelegate, your style sheet should work:

QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
combo->setItemDelegate(itemDelegate);

Important: If you change the model, then that will reset the view's delegate, so the above method needs to be called after any call to setModel().

like image 132
Leiaz Avatar answered Oct 06 '22 11:10

Leiaz


An alternative solution would be:

ui->comboBox->model()->setData(ui->comboBox->model()->index(-row-, 0), QSize(-width-, -height-), Qt::SizeHintRole);

, where -row- is zero-based item index; -width- and -height- stand for item width hint and height hint, respectively.

like image 27
guan boshen Avatar answered Oct 06 '22 13:10

guan boshen