Results 1 to 9 of 9

Thread: How to add image in QListWidget

  1. #1
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to add image in QListWidget

    Hello

    I have some lines passed in a QListWidget using listWidget->addItem ( dog ),listWidget->addItem ( cat ) etc..

    Can someone tell me how can i add a picture near the text??
    Thanks!

  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: How to add image in QListWidget

    see the QTDIR\examples\itemviews\stardelegate\ example.

  3. #3
    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: How to add image in QListWidget

    or QTDIR\demos\interview\

  4. #4
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add image in QListWidget

    not helpful..i have the pictures already in the resources.qrc.Just need a method to display them in the listwidget as items..any hint?

  5. #5
    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: How to add image in QListWidget

    Qt Code:
    1. QVariant Model::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid())
    4. return QVariant();
    5. static QIcon services(QPixmap(":/images/yourimage.png"));
    6. if (role == Qt::DecorationRole)
    7. return qVariantFromValue(services);
    8. return QVariant();
    9. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add image in QListWidget

    there is no need to pass the images through index..
    the code is like
    Qt Code:
    1. ...
    2. QListWidgetItem* dog = new QListWidgetItem ( tr ( ""its a dog ) );
    3. QListWidgetItem* cat = new QListWidgetItem ( tr ( "its a cat" ) );
    4. QListWidgetItem* lion = new QListWidgetItem ( tr ( "its a lion" ) );
    5. //just need to construct 3 image items here
    6. list->addItem(dog);
    7. list->addItem(cat);
    8. list->addItem(lion);
    9. //and pass them here for every animal
    To copy to clipboard, switch view to plain text mode 

  7. #7
    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: How to add image in QListWidget

    maybe this code will help
    Qt Code:
    1. QListWidget *lw = new QListWidget(this);
    2. QListWidgetItem *itm = new QListWidgetItem(tr("one"));
    3. itm->setIcon(QIcon(":/images/image.png"));
    4. lw->addItem(itm);
    To copy to clipboard, switch view to plain text mode 

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

    mekos (4th August 2008)

  9. #8
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add image in QListWidget

    You're very helful today my friend thanks!
    Do you know how to resize a specified column in a treeview?

  10. #9
    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: How to add image in QListWidget

    read more about this method
    Qt Code:
    1. void QHeaderView::setResizeMode ( int logicalIndex, ResizeMode mode )
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. void QHeaderView::resizeSection ( int logicalIndex, int size )
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Need Image rightside of QListwidget
    By rajeshs in forum Qt Programming
    Replies: 18
    Last Post: 12th February 2013, 20:46
  2. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  3. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  4. Replies: 13
    Last Post: 15th December 2006, 11:52
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.