Results 1 to 2 of 2

Thread: Showing Pixmap as a QListWidget Item

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Showing Pixmap as a QListWidget Item

    Hi All,

    I m using Qt 4.2.2 on my Intel Mac.
    I want to show a image as a QListWidget Item.That is the Pixmap of the Image should be set as a QListWidgetItem.

    I m doing the following....

    QPixmap NoPreViewpix(QDir::currentPath () +":/images/NoPreView.png");
    QIcon NoIcon(NoPreViewpix);

    listWidget->setViewMode(QListView::IconMode);
    QListWidgetItem *LWidgetItem
    = new QListWidgetItem(NoIcon,"Image Name",listWidget,0);

    listWidget->insertItem(0, LWidgetItem);


    But It is not showing any Image only showing the string ImageName .

    Could I set the Pixmap Image in the QListWidget or I have to use another Widget for that.

    If any one know then plz help me.

    Thanks.

  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: Showing Pixmap as a QListWidget Item

    Hi, so are you using resources? Do you have a .qrc file?

    If you are using resources it should be something more like this:
    Qt Code:
    1. QPixmap NoPreViewpix(":/images/NoPreView.png");
    To copy to clipboard, switch view to plain text mode 
    Resources are compiled into the application binary.

    If you are not using resources, the more appropriate way would be:
    Qt Code:
    1. QPixmap NoPreViewpix(QApplication::applicationDirPath() + "/images/NoPreView.png");
    To copy to clipboard, switch view to plain text mode 
    Notice the missing ":" (used only with resources). In addition, the current working directory might not be reliable as it's not necessarily the same directory where the application binary is located in.
    J-P Nurmi

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

    vishal.chauhan (2nd February 2007)

Similar Threads

  1. Replies: 13
    Last Post: 15th December 2006, 11:52
  2. Replies: 3
    Last Post: 7th November 2006, 08:35
  3. Reg - add item in QListWidget
    By suresh in forum Newbie
    Replies: 1
    Last Post: 1st September 2006, 17:52
  4. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 19:41
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 09:56

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.