PDA

View Full Version : display filename



kamlmish
21st December 2010, 10:19
Hi
I have a small code where I am able to display the images



void FrameDisplay::populate()
{
QDir dir("/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes");
dir.setFilter(QDir::Files);
QImage thumb, tmp;
int sizeW = 32;
int sizeH = 32;
QStringList listfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i=0;i<listfiles.count();i++)
{
modl->setRowCount(listfiles.count());
modl->setColumnCount(2);
QString filename = listfiles.at(i);
QString filepath = dir.absoluteFilePath(filename);
bool x = tmp.load(filepath);
//bool x = tmp.load("/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes/Black Hexagon.png");
if(x == true)
{
thumb = (tmp.scaled( 240, 480 ).scaled( sizeW, sizeH, Qt::IgnoreAspectRatio )); //two passes
modl->setData( modl->index( i, 0 ), thumb, Qt::DecorationRole );
}

}
//listwidget->addItems(listfiles);
viw->setModel(modl);
viw->show();

}






But I also need to display the filenames with the images
How should I setdata for the model to display the filenames also ?

Please help

squidge
21st December 2010, 13:31
Have you tried to use an additional role? Eg. DisplayRole

kamlmish
22nd December 2010, 04:00
HI
Solved the issue

by adding the line

modl->setData( modl->index( i, 1 ), filename, Qt::DecorationRole );