
Originally Posted by
d_stranz
QAbstractTableModel does not re-implement setData(), so it is using the implementation from its base class, QAbstractItemModel. The documentation for
QAbstractItemModel::setData() says:
So if you have not implemented setData() in your own model (derived from QAbstractTableModel), then using the default setData() method is doing nothing to store your string.
This tutorial would be a good place to start. There is a section on creating an editable model.
Sorry I had misunderstood your previous message.
Yes I implemented a setData from my model.
I write it below:
{
if (!index.isValid())
{
return false;
}
if (role == Qt::EditRole)
{
m_reports[index.row()].replace("actionName", value.toString());
emit dataChanged(index, index);
return true;
}
}
bool SelectedListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
{
return false;
}
if (role == Qt::EditRole)
{
m_reports[index.row()].replace("actionName", value.toString());
emit dataChanged(index, index);
return true;
}
}
To copy to clipboard, switch view to plain text mode
It is not clear to me how to add data with a custom role.
Can you help me with a small example?
Bookmarks