PDA

View Full Version : QAbstractListModel and icon problem



mchrk
10th March 2009, 20:20
Hello,

I have created QAbstractListModel in the data function I check for the DecorationRole and when that is passed to the function I check for the right column and return a pixmap but I can't get it to work



QVariant
ResultModel::data(const QModelIndex& index, int role) const
{
if(!index.isValid())
return QVariant();

if(Qt::DisplayRole != role)
return QVariant();

ResultItem item = fItems.at(index.row());


if(Qt::DisplayRole == role)
{
if(kColumnFileName == index.column())
return item.file().fileName();

if(kColumnExpectedChecksum == index.column())
return item.expectedChecksum();

if(kColumnCalculatedChecksum == index.column())
return item.calculatedChecksum();

}

// does not work
//
else if(Qt::DecorationRole == role)
{
TRACE("Decoration column: %d\n", index.column());

if(kColumnStatus == index.column())
{
int status = item.status();

TRACE("Choosing error: %d\n", status);

if(ResultItem::kStatusOk == status)
return QPixmap(":/images/ok.png");
}
}

return QVariant();
}


As you can see I print som trace message when the DecorationRole is suposed to run but I get nothing, it never runs. I know there isn't much info but what can I have done wrong?

wysota
10th March 2009, 22:42
Look at lines 6 and 7 of the snippet.

mchrk
11th March 2009, 12:21
Haha thank you, i feel so stupid right now :D