PDA

View Full Version : ComboBox QStyle



deMarco
21st February 2009, 07:23
Hi,
I'm reimplementing the style for a combobox, but can't figure out how to override the list popup that appears when you click on the arrow..

Screenshot attached.. you can see my PE_Frame drawn around the list, but the background is still white, and i'd like to override that to black to match the rest of the box..

I've put a breakpoint on my drawControl, drawPrimitive etc methods but they're not being triggered when the list opens (except for the PE_Frame). I can't find any clues in the Qt source for this particular part of comboboxes.. so i'm abit stuck on this one, any ideas?

talk2amulya
21st February 2009, 07:35
QAbstractItemView * QComboBox::view () const

Returns the list view used for the combobox popup.

See also setView().

this is the view of the listbox u see after u click on the down button..u should use this view to draw ur background color..should be pretty simple

talk2amulya
21st February 2009, 07:37
to be more specific, try using

void QWidget::setBackgroundRole ( QPalette::ColorRole role )

on the view that u get from view()

Cruz
21st February 2009, 10:30
Why don't you use style sheets (http://doc.trolltech.com/4.4/stylesheet.html) to customize the looks of your combo box? You could do away without any coding at all.

talk2amulya
21st February 2009, 10:47
i guess u chose not to do using stylesheets cuz either u hv an older version of qt..or u just didnt know u can do it other ways :) here is how u do using stylesheets:

QComboBox QAbstractItemView{
background-color: black;
}

for further reference: http://doc.trolltech.com/4.3/stylesheet.html

deMarco
21st February 2009, 23:32
great, thanks guys.. turned out to be the QPalette::Base colour. I missed this little snippet in the documentation:


Used mostly as the background color for text entry widgets, but can also be used
for other painting - such as the background of combobox drop down lists and toolbar
handles. It is usually white or another light color.

and no i didn't know about style sheets, will definately read up on them for my next project.. i've done too much qstyle work on this one to change over :)

vkincaid
11th January 2010, 17:18
I'm trying to use style sheets to add spaces before and after each drop down item so that it can be selected more easily with a finger in a touch screen but haven't found out how. Does anyone know what the right option is?

Here's my stylesheet for QComboBox:



QComboBox {
color: white;
border-color: white;
background-color: qlineargradient(x1: 0, y1: 0, x2:0, y2: 1, stop: 0 beige, stop: 1 black);
border: 1px solid white;
border-radius: 3px;
padding: 1px 18px 1px 3px;
min-width: 6em;
font: 15pt "Sans Serif";
}

QComboBox QAbstractItemView {
border: 2px solid darkgray;
color: white;
padding: 10px 10px 10px 10px;
selection-background-color: lightgray;
}