PDA

View Full Version : Showing Pixmap as a QListWidget Item



vishal.chauhan
1st February 2007, 13:16
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.

jpn
1st February 2007, 13:25
Hi, so are you using resources? Do you have a .qrc file?

If you are using resources it should be something more like this:


QPixmap NoPreViewpix(":/images/NoPreView.png");

Resources are compiled into the application binary.

If you are not using resources, the more appropriate way would be:


QPixmap NoPreViewpix(QApplication::applicationDirPath() + "/images/NoPreView.png");

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.