PDA

View Full Version : [CSS/QCombobox] setting min-height for drop down list



Boy
9th May 2008, 12:30
Hi,

I want to set the minimal height of an item of the drop down list of a QComboBox via a cascade style sheet. There seems to be no way to do this, but still I want to check if someone has any clue how to do this.

You can set the min-height for the combobox itself, but not for the dropdownlist.

to be clear: I don't want to increase the size of the font, just the space between the different items (for touch-screen purposes...)

Aristomastrosi
15th May 2008, 08:58
I have exactly the same problem. I tried a lot of different styles to apply, but none of them worked. In my opinion, the following CSS should work, but it doesn't:


QComboBox QAbstractItemView::item
{
padding-top: 10px;
padding-bottom: 10px;
}

I tried also the tip from another thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-styling-each-item-in-a-qcombobox-12025.html) to add the QApplication::globalStrut. This works for all Widgets, except AbstractItemView of the QComboBox.

I'm at the moment with Qt 4.3.2, and will try it today with Qt 4.4.

One solution would be to implement a custom model. But it would be so nice if I don't have to implement a custom model.

MarkRus
30th July 2010, 14:32
Solution is (at least for Qt 4.6.0):



setStyleSheet("QComboBox { min-height: 40px; min-width: 60px; }"
"QComboBox QAbstractItemView::item { min-height: 40px; min-width: 60px; }");
QComboBox *combo = new QComboBox(this);
combo->setView(new QListView());

if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view.

kope
29th April 2011, 18:49
Thanks very much for this solution.
Works too with 4.7.2, seems to still be the same bug.

æž—å©·
22nd August 2012, 10:59
It works!But I wonder if every QComboBox uses "combo->setView(new QListView());",Could it cause memory leak?

spirit
22nd August 2012, 11:03
It works!But I wonder if every QComboBox uses "combo->setView(new QListView());",Could it cause memory leak?
No, it couldn't.
The doc says:


Sets the view to be used in the combobox popup to the given itemView. The combobox takes ownership of the view.


Read about QComboBox::setView carefully.

Abel
29th April 2014, 04:04
Solution is (at least for Qt 4.6.0):



setStyleSheet("QComboBox { min-height: 40px; min-width: 60px; }"
"QComboBox QAbstractItemView::item { min-height: 40px; min-width: 60px; }");
QComboBox *combo = new QComboBox(this);
combo->setView(new QListView());

if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view.
if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view.
It should be higtligeted!.