Results 1 to 4 of 4

Thread: Easiest way to display icons in a table

  1. #1
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Easiest way to display icons in a table

    Hi there,

    while using a TableView and costum item delegates would be one way to display Icons in a table, I suspect there is a simpler way, possibly even with QTableWidget.

    However, when I simply create a new QTableWidgetItem with an Icon and insert it into the table, it won't be shown.

    The code below doesn't will insert a table widget item, but won't show the icon.
    Qt Code:
    1. QTableWidgetItem * iconItem = new QTableWidgetItem(QIcon(":/images/ok.png"), "");
    2. table->setItem(row, 0, iconItem);
    To copy to clipboard, switch view to plain text mode 

    So, what would be the correct (and simplest) way to show Icons in a Table?
    Andreas

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Easiest way to display icons in a table

    Something pretty much similar works fine for me. I'm suspecting that the image just cannot be loaded. Is the usage of resources intentional? Are the resources compiled correctly? Do you have a line similar to:
    RESOURCES += <something>.qrc
    in the .pro file? RCC would give an error in case the image couldn't be found.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Easiest way to display icons in a table

    If you're using a TableView you can simply return a QIcon in your QAbstractItemModel's data function. That should display the icon you want in the table.

  4. #4
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Easiest way to display icons in a table

    Quote Originally Posted by jpn View Post
    Something pretty much similar works fine for me. I'm suspecting that the image just cannot be loaded.
    Yes, that was it. Works now as it is supposed to. Thanks!
    Andreas

Similar Threads

  1. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  2. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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.