Beispiel #1
0
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;
}
Beispiel #3
0
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);
    }
}