Originally Posted by
anda_skoa
My suggestion was to use a QFileDialog instance and set your own QFileIconProvider, i.e. one that implemens the icon(QFileInfo) function such that it creates a preview image of the file.
Of course you can implement your own file dialog as well, but that will be quite some work.
Cheers,
__
hi, I try to Inheritance QFileIconProvider and over write icon function, this is my code
public:
{
//if the file is image
if( info.suffix().compare("jpg",Qt::CaseInsensitive)==0 ||
info.suffix().compare("bmp",Qt::CaseInsensitive)==0 ||
info.suffix().compare("png",Qt::CaseInsensitive)==0 ||
info.suffix().compare("jpeg",Qt::CaseInsensitive)==0 )
{
//creat a preview image to QIcon
QIcon myIcon
(info.
filePath());
return myIcon;
}
}
//if the file is not image, return default icon
}
};
class myFileIconProvider:public QFileIconProvider {
public:
QIcon icon(const QFileInfo &info) const{
if(!QFileInfo(info.filePath()).isDir())
{
//if the file is image
if( info.suffix().compare("jpg",Qt::CaseInsensitive)==0 ||
info.suffix().compare("bmp",Qt::CaseInsensitive)==0 ||
info.suffix().compare("png",Qt::CaseInsensitive)==0 ||
info.suffix().compare("jpeg",Qt::CaseInsensitive)==0 )
{
//creat a preview image to QIcon
QIcon myIcon(info.filePath());
return myIcon;
}
}
//if the file is not image, return default icon
return QFileIconProvider::icon(info);
}
};
To copy to clipboard, switch view to plain text mode
myFileIconProvider fileIconProvider;
QFileSystemModel fileSystemModel;
fileSystemModel.setIconProvider(&fileIconProvider);
ui->listView_file->setModel(fileSystemModel);
myFileIconProvider fileIconProvider;
QFileSystemModel fileSystemModel;
fileSystemModel.setIconProvider(&fileIconProvider);
ui->listView_file->setModel(fileSystemModel);
To copy to clipboard, switch view to plain text mode
0000.jpg
it look good, but some problem in program
if the file is too much, then the ui->listView_file (QListView) will delay for a few second,
I think maybe icon function draw the QIcon was slowly,
if I go into a folder has 20 image, than the program will delay 2-3 second ˇ_ˇ
anyway, I am very grateful for your help
Bookmarks