tags:

views:

42

answers:

1

Hi..

i am new to QT, i am facing some problems in inserting images to list view.

can you please figure what is the problem in code snippet

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

   QListWidget* list=new QListWidget();
   QListWidgetItem *item1=new QListWidgetItem(QIcon(":\temp\boat.png"),"BlueHills",list);
   list->insertItem(0,item1);
   QListWidgetItem *item2=new QListWidgetItem(QIcon("C:\\Documents and Settings\\admin\\Desktop\\icons\\car.png"),"Sunset",list);



   list->show();

in the following code, i am able to put only text, images are not getting displayed. even nokia forum suggested this way only

FYI i have given linkes below

How to insert image1

how to insert image2

please suggest me how to put images and text in listview of QT

+1  A: 

Hey,

I took your code and pasted it in a brand new QtCreator project and it works...

I would suggest you double check your image's pathes !

Your first item has an image's path that should be ":/temp/boat.png"... And you have to make sure that your image is clearly defined in your ressource file. I would therefore suggest you to test with image at the root of C: -> "C://mypic.png".

If you want to use a ressource file, then here is an example :

<RCC>
    <qresource prefix="images_section">
        <file alias="MyBoatImage">boat.png</file>
    </qresource>
</RCC>

This has to be written in a file called ressource.qrc and be carefully specified in your .PRO file :

RESOURCES += ressource.qrc

Then an example of use in the code : ":/images_section/MyBoatImage"

Andy M
Hey.. andy Thanks for the reply dude..finally it worked..in order to access the resource we need to give resource prefix, then we need to access the resource.. the example which you have mentioned hepled lot.. Thanks
Shadow
Hey... no problem, glad it helped you ! See you!
Andy M