PDA

View Full Version : Display Images in a TREEVIEW



kamlmish
1st December 2010, 06:24
Hi All

I have a function where I am able to browse through specified directory (that contain images)

/************************************************** *****************/
void FrameDisplay::BrowseAndShow()
{
QDir dir("/home/kamlesh/Gall/GALL/images");
dir.setFilter(QDir::Files);
window = new QWidget;
foreach( const QFileInfo& entry, dir.entryInfoList( QStringList()<< "*.png", QDir::Files) )
{
QString imgName = entry.fileName();
QGridLayout* grid = new QGridLayout;
QLabel* label = new QLabel(this);
label->setPixmap(QPixmap(imgName));
grid->addWidget(label);
window->setLayout(grid);
window->setGeometry(20,20,20,30);
window->show();

}

}

/************************************************** ****************/

I need a way to display the images in a treeview structure e.g

/****************************************/

image1 image2
filename filename

image3 image4
filename filename

/****************************************/

How should I go about it?
Attached is the application GALL.zip and the macos style pdf for reference

bothorsen
1st December 2010, 15:03
Create a tree model (*) and use Qt::DecorationRole in data() to set the icon.

From your pdf file, I'm not sure if you can get away with a list model, though. It's worth trying, since those are a lot easier than tree models.

(*) This is in itself quite difficult. Look at the Qt docs for info on how to do that. And take heart by knowing that you will be very pleased with the model and your code once it works.

kamlmish
2nd December 2010, 04:41
I need a small example of table model
And secondly the images to be displayed are from a directory. There fore, how can I create a table for the same.