The role you need to use in QAbstractItemModel::data is Qt::CheckStateRole. I think the method should look like this:
{
if (!index.isValid())
{
}
QVariant val
= rec.
value(index.
column());
switch (role)
{
case Qt::CheckStateRole:
if (index.column() != 6)
else if (val.toInt() == 0) // or whatever
return Qt::Unchecked;
else
return Qt::Checked;
case Qt::DisplayRole:
return val;
default:
}
}
QVariant PurchaseOrdersRequests::data ( const QModelIndex & index, int role ) const
{
if (!index.isValid())
{
return QVariant();
}
QSqlRecord rec = record(index.row());
QVariant val = rec.value(index.column());
switch (role)
{
case Qt::CheckStateRole:
if (index.column() != 6)
return QVariant();
else if (val.toInt() == 0) // or whatever
return Qt::Unchecked;
else
return Qt::Checked;
case Qt::DisplayRole:
return val;
default:
return QVariant();
}
}
To copy to clipboard, switch view to plain text mode
Depending on the type stored in val, QVariant::toString() may well return an empty string. Use QVariant::typeName() to check what type it is. I think it's best to just pass on the QVariant value.
No guarantees, I did not check the code above, but I hope it gives you an idea.
Bookmarks