Problem with storing data of QTableView to QSatndardItemModel which has delegate
Hi,
I'm using a QTableView to present data of QStandardItemModel. I'm using a combobox delegate for the second column. I want to store data in my custom data structure too. However when I catch the itemChanged(QStandardItem*) signal I don't get the current value of the cell (data = "", which is not in the column 1). But the data entered in these columns remains even the selected cell changed. So they are stored in the model. When I do a run time debug I found that setModelData only emitted if the combobox changed. In normal cell editing this signal is not emitting.
Here's the code fragment to clear up.
Code:
//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;
}
}