QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { QComboBox *comboDelegate = new QComboBox(parent); comboDelegate->setModel(model); comboDelegate->setEditable(true); comboDelegate->setAutoCompletion(true); comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion); comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers); comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this))); comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this))); connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString))); connect(comboDelegate->lineEdit(), SIGNAL(editingFinished()), this, SLOT(testActivation())); connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation())); currCombo.comboEditor = comboDelegate; currCombo.currRow = index.row(); currCombo.model = const_cast<QAbstractItemModel*>(index.model()); // Current display of things on Gnome3 looks like shit, so // let`s fix that. if (isGnome3Session()) { QPalette p; p.setColor(QPalette::Window, QColor(Qt::white)); p.setColor(QPalette::Base, QColor(Qt::white)); comboDelegate->lineEdit()->setPalette(p); comboDelegate->setPalette(p); } return comboDelegate; }
void IColDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QComboBox *comboBox = qobject_cast<QComboBox *>(editor); if (!comboBox) return; int pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly); if( pos != -1){ comboBox->setCurrentIndex(pos); } else{ comboBox->addItem(index.model()->data(index).toString()); pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly); comboBox->setCurrentIndex(pos); } if( _p->isActive() ){ //set background color _parent->currentItem()->setBackgroundColor( _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ? QColor(184,16,0,180) : QColor(32,140,64,180) ); //set background color from (combobox) QPalette pal = comboBox->palette(); pal.setColor(QPalette::Base, _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ? QColor(164,32,16) : QColor(32,140,64) ); pal.setColor(QPalette::Text, QColor(255,255,255) ); comboBox->setPalette(pal); } }
QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex & index) const { /*QSpinBox *editor = new QSpinBox(parent); editor->setFrame(false); editor->setMinimum(0); editor->setMaximum(100);*/ QComboBox *editor = new QComboBox(parent); QPalette pal = editor->palette(); pal.setColor(QPalette::HighlightedText, QColor(Qt::white)); editor->setPalette(pal); //editor->addItems((QStringList() << list_defTcontrol)); return editor; }
void IColDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QComboBox *comboBox = qobject_cast<QComboBox *>(editor); if (!comboBox) return; model->setData(index, comboBox->currentText()); //update the processor _p->getCols( INPUT, _name )[ index.row() ]->setValue( comboBox->currentText().toStdString() ); _msc->consistencyCheck(); if( _p->isActive() ){ //set background color _parent->currentItem()->setBackgroundColor( _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ? QColor(184,16,0,180) : QColor(32,140,64,180) ); //set background color from (combobox) QPalette pal = comboBox->palette(); pal.setColor(QPalette::Base, _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ? QColor(164,32,16) : QColor(32,140,64) ); pal.setColor(QPalette::Text, QColor(255,255,255) ); comboBox->setPalette(pal); } }