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"));
}
}
//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"));
}
}
To copy to clipboard, switch view to plain text mode
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"));
}
//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"));
}
To copy to clipboard, switch view to plain text mode
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)?
Bookmarks