PDA

View Full Version : Style Sheet color of QComboBox



tpf80
23rd June 2007, 03:13
I created the following slot, and code to link the signal I wanted to it:



//connection:
connect(ui.vendor_status, SIGNAL( activated (int) ), this, SLOT(colorBackgroundcombo() ) );


// slot:
//color the background of the combo box that called the slot:
void FabwareMain::colorBackgroundcombo() {
//enable the save button since we have edited something:
ui.actionSave->setEnabled(true);
//color the combobox yellow since we changed it
QComboBox* comboBox = qobject_cast<QComboBox*>(sender());
if (comboBox) {
comboBox->setStyleSheet(QString("background-color: yellow"));
}
}

The program compiled fine, however when executed only ui.actionSave is set to true when any of the comboboxes that are connected to this slot are changed.

I then did an experiment and changed the slot to this:
(the slot would change a style of a specific combobox and line edit field instead of using sender())


//color the background of the combo box that called the slot:
void FabwareMain::colorBackgroundcombo() {
//enable the save button since we have edited something:
ui.actionSave->setEnabled(true);
ui.vendor_state->setStyleSheet(QString("background-color: yellow"));
ui.vendor_zip->setStyleSheet(QString("background-color: yellow"));
}

After changing to my test slot, when the slot is called, actionSave is enabled, vendor_zip is colored to yellow, however the QComboBox vendor_state is still white.

I would think this means that for some reason the QComboBox is not taking the style from setStyleSheet(), however I can find no error output either during runtime or compile that would indicate why.

Could anyone point me in the right direction on the stylesheet for QComboBox, (or an alternate coloring method if the styles do not work for it)?

wysota
24th June 2007, 10:20
Do you use 4.2 or 4.3? And which widget style?

tpf80
24th June 2007, 10:40
I am using QT 4.2.3 open source and the issue happens when I compile on windows XP (I assume thats what you mean by "widget style". If you would like I can also see what happens in linux as I have everything set up to compile for that as well.

wysota
24th June 2007, 10:42
Run your application with -style Plastique parameters and see if the behaviour persists.

tpf80
24th June 2007, 11:21
Ok, Heres something interesting. I ran it in all styles including plastique to see what would happen, and I got the exact same results as I described with the windows XP style, except in the CDE style. Heres what happened:

-When the form is untouched in CDE and classic windows style, the comboboxes are raised, but they are white. When the test slot is activated, the ui.vendor_state combobox becomes grey, and the ui.vendor_zip line edit becomes yellow.

-In the classic windows style, the same thing happens as in the CDE, except instead of the whole combobox turning grey on activation of the slot, only the tiny drop arrow on the right hand side turns from white to grey.

I notice that the plastique or cleanlooks style, the comboboxes are a shiny gray color when you are not in the process of selecting an item from them. It seems like this can't be changed.

In the windows XP style, the comboboxes are text with a white background but still won't take the style. They look like they could be changed, but maybe they somehow inherit the same traits as plastique/cleanlooks.

wysota
24th June 2007, 11:46
I suggest you upgrade your Qt installation. You might be suffering from some kind of bug. Stylesheets are a quite new technology in Qt and still contain many bugs. The sheet seems to work fine on my 4.3-based installation.

tpf80
25th June 2007, 02:55
Yes that fixed it, after upgrading to Qt 4.3 and re-compiling my program, the QComboBox takes the style like expected.