Results 1 to 3 of 3

Thread: QAbstractListModel and icon problem

  1. #1
    Join Date
    May 2008
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QAbstractListModel and icon problem

    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

    Qt Code:
    1. ResultModel::data(const QModelIndex& index, int role) const
    2. {
    3. if(!index.isValid())
    4. return QVariant();
    5.  
    6. if(Qt::DisplayRole != role)
    7. return QVariant();
    8.  
    9. ResultItem item = fItems.at(index.row());
    10.  
    11.  
    12. if(Qt::DisplayRole == role)
    13. {
    14. if(kColumnFileName == index.column())
    15. return item.file().fileName();
    16.  
    17. if(kColumnExpectedChecksum == index.column())
    18. return item.expectedChecksum();
    19.  
    20. if(kColumnCalculatedChecksum == index.column())
    21. return item.calculatedChecksum();
    22.  
    23. }
    24.  
    25. // does not work
    26. //
    27. else if(Qt::DecorationRole == role)
    28. {
    29. TRACE("Decoration column: %d\n", index.column());
    30.  
    31. if(kColumnStatus == index.column())
    32. {
    33. int status = item.status();
    34.  
    35. TRACE("Choosing error: %d\n", status);
    36.  
    37. if(ResultItem::kStatusOk == status)
    38. return QPixmap(":/images/ok.png");
    39. }
    40. }
    41.  
    42. return QVariant();
    43. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractListModel and icon problem

    Look at lines 6 and 7 of the snippet.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2008
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QAbstractListModel and icon problem

    Haha thank you, i feel so stupid right now

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.