qCmBxStates = new QComboBox();qCmBxStates->setFixedWidth(WIDTH_COMBO);connect(qCmBxStates, SIGNAL(activated(int)), this, SLOT(updateState(int)));statesModel = new ListDataModel(loodsman, qLstStates, this);qCmBxStates->setModel(statesModel);void SearchWidget::updateState(int row){ QPalette pal; pal.setColor(QPalette::Button, getColorState(qLstStates, row, 0)); qCmBxStates->setPalette(pal);}
void SearchWidget::updateState(int row){ qCmBxStates->setStyleSheet(getColorState(QString("QComboBox"), qLstStates, row, 0));}QString getColorState(QString type, QList<QStringList> *list, int row, int pos){ if(list->at(row).at(pos) == QObject::tr("Архив") || list->at(row).at(pos) == QObject::tr("Архив без проверки состава") || list->at(row).at(pos) == QObject::tr("Утвержден")) return QString(type + "{background-color:rgb(226, 255, 197)}"); else if(list->at(row).at(pos) == QObject::tr("Серия")) return QString(type + "{background-color:rgb(197, 197, 226)}"); else if(list->at(row).at(pos) == QObject::tr("Аннулирован")) return QString(type + "{background-color:rgb(255, 226, 197)}"); else if(list->at(row).at(pos) == QObject::tr("Макет")) return QString(type + "{background-color:rgb(226, 197, 226)}"); else if(list->at(row).at(pos) == QObject::tr("Проектирование")) return QString(type + "{background-color:rgb(255, 255, 0)}"); return QString(type + "{background-color:rgb(255, 255, 255)}");}
QModelIndex index = qCmBxStates->model()->index(row, 0);QVariant data = qCmBxStates->model()->data(index, Qt::BackgroundRole);QBrush brush = qVariantValue<QBrush>(data);QColor color = brush.color();
QPalette palette = qCmBxStates->palette();palette.setColor(QPalette::Normal, qCmBxStates->backgroundRole(), color);qCmBxStates->setPalette(palette);