//Model
p_TableFields->insertColumns(0, 4);
p_TableFields->insertRows(0, 3);
//Table View
tblFields->setModel(p_TableFields);
//ComboBox delegation for column 1
p_delegate = new DelegateComboBox(tblFields);
tblFields->setItemDelegateForColumn(1, p_delegate);
//Signal for data change
//Cell Edited function
QString value
= item
->data
().
toString();
//this is ""(empty)
//Custom delegation - Only fired for column 1
{
if ( index.column() == 1 )
{
QComboBox *comboBox
= static_cast<QComboBox
*>
(editor
);
QString str
= comboBox
->currentText
();
if ( str.compare("<select>") )
model->setData(index, str);
return;
}
}
//Model
p_TableFields = new QStandardItemModel(this);
p_TableFields->insertColumns(0, 4);
p_TableFields->insertRows(0, 3);
//Table View
tblFields->setModel(p_TableFields);
//ComboBox delegation for column 1
p_delegate = new DelegateComboBox(tblFields);
tblFields->setItemDelegateForColumn(1, p_delegate);
//Signal for data change
connect(p_TableFields, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(CellEdited(QStandardItem*)));
//Cell Edited function
QString value = item->data().toString(); //this is ""(empty)
//Custom delegation - Only fired for column 1
setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index ) const
{
if ( index.column() == 1 )
{
QComboBox *comboBox = static_cast<QComboBox*>(editor);
QString str = comboBox->currentText();
if ( str.compare("<select>") )
model->setData(index, str);
return;
}
QItemDelegate::setModelData(editor, model, index);
}
To copy to clipboard, switch view to plain text mode
Bookmarks