Thanks for your replay,
I implemented data and setdata from your example. But the data in the proxy column is not editable.
Even when i reimplemented flags the column stayed gray and did not call setdata.
EDIT sloved graynes by returning Qt::ItemIsEnabled flag EDIT
What I'm doing wrong?
compiling the code with qt 5 i got an error on row 74.
return createIndex(row, column, 0);
call of overloaded 'createIndex(int&, int&, int)' is ambiguous
so i used the default. createIndex(int&, int&)
{
if((index.column() <= 0) and (role == Qt::DisplayRole)){
//return QString("Proxy Data - Row:%1").arg(index.row());
for (int i = 0; i < LastColumn.count();++i){
if (LastColumn[i].first == index.row())
return LastColumn[i].second;
}
}
return sourceModel()->data(mapToSource(index), role);
}
{
qDebug() << "setdata";
if((index.column() <= 0) and (role == Qt::EditRole))
{
// TODO: store data into ProxyModel
for ( int i = 0; i < LastColumn.count();++i){
if (LastColumn[i].first == index.row()){
LastColumn.removeAt(i);
LastColumn.append(qMakePair(index.row(),value.toString()));
return true;
}
}
LastColumn.append(qMakePair(index.row(),value.toString()));
return true;
}
return sourceModel()->setData(mapToSource(index), role);
}
Qt
::ItemFlags flags
( const QModelIndex & index
) const{
if (index.column() <= 0){
return (Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
}
private:
QList<QPair<int,QString> > LastColumn;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
{
if((index.column() <= 0) and (role == Qt::DisplayRole)){
//return QString("Proxy Data - Row:%1").arg(index.row());
for (int i = 0; i < LastColumn.count();++i){
if (LastColumn[i].first == index.row())
return LastColumn[i].second;
}
return QString("temp");
}
return sourceModel()->data(mapToSource(index), role);
}
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
{
qDebug() << "setdata";
if((index.column() <= 0) and (role == Qt::EditRole))
{
// TODO: store data into ProxyModel
for ( int i = 0; i < LastColumn.count();++i){
if (LastColumn[i].first == index.row()){
LastColumn.removeAt(i);
LastColumn.append(qMakePair(index.row(),value.toString()));
return true;
}
}
LastColumn.append(qMakePair(index.row(),value.toString()));
return true;
}
return sourceModel()->setData(mapToSource(index), role);
}
Qt::ItemFlags flags ( const QModelIndex & index ) const{
if (index.column() <= 0){
return (Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
return QAbstractProxyModel::flags(index);
}
private:
QList<QPair<int,QString> > LastColumn;
To copy to clipboard, switch view to plain text mode
Bookmarks