Results 1 to 4 of 4

Thread: Displaying icon in tableView

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Displaying icon in tableView

    Hi

    I'm trying to display an icon in a tableview cell. I've search this forum but only found one thread related to it:
    http://www.qtcentre.org/forum/showth...icon+tableview

    However this does not help me since that was a tableWidget. I've created a model class inheriting from QAbstractTableModel and in the data() function I'm trying to return a QIcon. I thought this would work since the data function returns a QVariant which should suit a QIcon.

    This is the code that is located in my model's data function:
    Qt Code:
    1. if (role == Qt::DisplayRole) {
    2. QIcon icon = QIcon(":/images/error.png");
    3. return icon
    4. }
    To copy to clipboard, switch view to plain text mode 

    Am I missing something? Can I use a .png file? This should be pretty easy to do shouldn't it?

    Thanks
    Jaco

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Displaying icon in tableView

    did you have resource file? is it included in pro file?

  3. The following user says thank you to spirit for this useful post:

    JPNaude (14th October 2008)

  4. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Displaying icon in tableView

    return the icon for the Qt::DecorationRole

  5. The following user says thank you to caduel for this useful post:

    JPNaude (14th October 2008)

  6. #4
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: Displaying icon in tableView

    Yes I had the resource file. I did not have the correct prefix in the resource file, and I also didn't return the icon under the DecorationRule. It works now.

    Thanks
    Jaco

Similar Threads

  1. QMessageBox missing icon
    By zanth in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2010, 21:20
  2. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03
  3. Mac application and the Dock Icon
    By sekelsenmat in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 10:23
  4. Displaying Icon
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 9th February 2006, 20:43

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.