Recently in the work often encountered a problem is to put the pictures in the folder in the form of thumbnails, the beginning of the confused, do not know how to do, after searching the information on the Internet, found that the qlistwidget control can achieve the thumbnail image display, But do not know how to use this control to achieve this function, there are many examples on the web, but on the Windows system with Qt compiled these programs, but not the ideal effect, Although these images can also be shown as thumbnails, but all of these images must be made into resource files, and the normal development of a lot of real-time images in the form of thumbnails to show a completely different. So looking for a few days, the final solution to this problem, the following is the implementation of the thumbnail display of the main code, only need to put the code into the slot function can be achieved all the pictures in the form of thumbnails display.
The code is as follows:
QString FilePath = TR ("/media/sd/pictures");
Qlistwidget *listwidget_file = new Qlistwidget (this);
Listwidget_file->setobjectname (Qstring::fromutf8 ("Listwidget_file"));
Listwidget_file->setgeometry (qrect (0, 0, 0, 0));
Qdiriterator M_diriterator (QString ("/media/sd/pictures"), qdir::files| Qdir::nosymlinks,qdiriterator::subdirectories);
Listwidget_file->clear ();//guaranteed to be empty every time you enter listwidget_file .
while (M_diriterator.hasnext ())
{
QString Tempfile=m_diriterator.next ();
Listwidget_file->seticonsize (qsize (100, 100)); //SetQlistwidgetThe picture size of the cell item in
Listwidget_file->setresizemode (Qlistview::adjust);
Listwidget_file->setviewmode (Qlistview::iconmode); //SetQlistwidgetthe display mode
Listwidget_file->setmovement (qlistview::static); //SetQlistwidgetcannot be dragged in a cell item
Listwidget_file->setspacing (10); //SetQlistwidgetThe spacing of the cell items in
Qpixmap Objpixmap (tempfile); generate image objpixmap
The/media/sd/pictures string in the tempfile is deleted and the remaining part is returned
Tempfile=tempfile.remove (QString ("/media/sd/pictures"), qt::casesensitive);
generating qlistwidgetitem Objects
Qlistwidgetitem *pitem = new Qlistwidgetitem (Qicon (objpixmap.scaled (qsize)), 100,100);
Pitem->setsizehint (Qsize (100,120)); set the width and height of a cell item
Listwidget_file->additem (Pitem); add qlistwidgetitem Item
}
Listwidget_file->setgeometry (null,null,480,272);
This code I run in the embedded version of QT success, and in the embedded device to achieve the desired target,theSd card images are all shown in the form of thumbnails.
Qlistwidget mode display thumbnail image