Results 1 to 4 of 4

Thread: Adding QPixmaps to QListView

  1. #1
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Exclamation Adding QPixmaps to QListView

    I am adding QPixmap objects to a QLIstView in a custom widget. I am using the following code to do it -

    Qt Code:
    1. mContentItemModel = new QStandardItemModel(this);
    2. ui->listView->setModel(mContentItemModel);
    3. ui->listView->clearSelection();
    4. ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
    5. ui->listView->setWordWrap(true);
    6.  
    7. QStandardItem* listitem1 = new QStandardItem();
    8. QStandardItem* listitem2 = new QStandardItem();
    9. QStandardItem* listitem3 = new QStandardItem();
    10.  
    11. QPixmap pmap1("c:\\thumbnail1.jpg");
    12. QVariant var1 = pmap1;
    13. QVariant var2 = pmap1;
    14. QVariant var3 = pmap1;
    15. listitem1->setData( var1, Qt::DisplayRole );
    16. listitem2->setData( var2, Qt::DisplayRole );
    17. listitem3->setData( var3, Qt::DisplayRole );
    18.  
    19. mContentItemModel->appendRow(listitem1);
    20. mContentItemModel->appendRow(listitem2);
    21. mContentItemModel->appendRow(listitem3);
    To copy to clipboard, switch view to plain text mode 

    When I run the application , the pixmaps are not displayed in the listview. Any idea what changes are required to display the pixmaps? Should i create a custom delegate class for this ?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding QPixmaps to QListView

    Try using QStandardItem::setIcon
    DisplayRole is meant as text.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Adding QPixmaps to QListView

    ...or use Qt:ecorationRole.

  4. #4
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Exclamation Re: Adding QPixmaps to QListView

    I tried using the setIcon API of QStandardItem API. But the image appears very small.. that is not what I want, i want the image to be bigger ( I should be able to control the size of the image). I want to have a custom widget being displayed there ... any solutions to this ?

Similar Threads

  1. Adding validation to a QListView's edit mode
    By MattT in forum Qt Programming
    Replies: 10
    Last Post: 1st August 2010, 01:53
  2. Adding elements to a QListView
    By Arreis in forum Newbie
    Replies: 4
    Last Post: 30th June 2009, 06:56
  3. How to merge two QPixmaps in to one.
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 17th August 2008, 13:59
  4. how to merge QPixmaps
    By tommy in forum Qt Programming
    Replies: 2
    Last Post: 27th March 2008, 12:02
  5. Are transparent QPixmaps possible?
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2007, 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.