Results 1 to 10 of 10

Thread: how to preview of image in QFileDialog by default

  1. #1
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default how to preview of image in QFileDialog by default

    hi,

    I am using QFileDialog::getOpenFileNames() in my code

    it is good to use in Windows 7
    01.jpg

    but I find a question in Windows XP, that is QFileDialog has no preview image,

    like this photo
    02.JPG

    I must manually open the preview from red circle every time when I use QFileDialog::getOpenFileNames()

    so I would like to ask is there any way to automatic open preview image?

    thanks a lot

    and, sorry for my bad English.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to preview of image in QFileDialog by default

    The two versions of the operating system probably have different default file dialogs, which is what Qt is using for its static convenience methods.

    You could experiement with creating a QFileDialog instance manually and providing a custom QFileIconProvder when on XP

    Cheers,
    _

  3. #3
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to preview of image in QFileDialog by default

    Quote Originally Posted by anda_skoa View Post
    The two versions of the operating system probably have different default file dialogs, which is what Qt is using for its static convenience methods.

    You could experiement with creating a QFileDialog instance manually and providing a custom QFileIconProvder when on XP

    Cheers,
    _

    Hi, thank you your answer

    today, I try to make FileDialog,

    I use QFileSystemModel in QListView


    Qt Code:
    1. QFileSystemModel *fileSystemModel = new QFileSystemModel();
    2. ui->listView_file->setModel(fileSystemModel);
    To copy to clipboard, switch view to plain text mode 

    this is a picture of my program
    001.jpg

    please help me again,

    I would like to ask how to let it show preview image on QListView?

    like QFileDialog have preview image
    01.jpg


    thank you very much
    Last edited by yoll522; 27th April 2014 at 15:43.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to preview of image in QFileDialog by default

    Have you tried what I suggested?

    Cheers,
    _

  5. #5
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to preview of image in QFileDialog by default

    yes

    but I going to look QFileIconProvider document, it have "icon" function,

    it is to provide systematic image, like the following instructions

    Qt Code:
    1. enum QFileIconProvider::IconType
    To copy to clipboard, switch view to plain text mode 

    I try it to use, this is my code

    QFileIconProvider fileIcon;
    ui->pushButton->setIcon(fileIcon.icon(QFileInfo("1.jpg")));
    but I got this answer
    002.jpg

    it also have no preview Image

    maybe I was wrong about something

    could you please guide me

    thanks you very much

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to preview of image in QFileDialog by default

    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,
    __

  7. #7
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to preview of image in QFileDialog by default

    Quote Originally Posted by anda_skoa View Post
    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

    Qt Code:
    1. class myFileIconProvider:public QFileIconProvider {
    2. public:
    3. QIcon icon(const QFileInfo &info) const{
    4. if(!QFileInfo(info.filePath()).isDir())
    5. {
    6. //if the file is image
    7. if( info.suffix().compare("jpg",Qt::CaseInsensitive)==0 ||
    8. info.suffix().compare("bmp",Qt::CaseInsensitive)==0 ||
    9. info.suffix().compare("png",Qt::CaseInsensitive)==0 ||
    10. info.suffix().compare("jpeg",Qt::CaseInsensitive)==0 )
    11. {
    12. //creat a preview image to QIcon
    13. QIcon myIcon(info.filePath());
    14. return myIcon;
    15. }
    16. }
    17. //if the file is not image, return default icon
    18. return QFileIconProvider::icon(info);
    19. }
    20. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. myFileIconProvider fileIconProvider;
    2. QFileSystemModel fileSystemModel;
    3. fileSystemModel.setIconProvider(&fileIconProvider);
    4.  
    5. 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

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to preview of image in QFileDialog by default

    Hmm.

    Another option might be a class derived from QFileSystemModel or a QIdentityProxyModel subclass on top of a normal QFileSystemModel.

    When an icon for a file (Qt:ecorationRole) is requested, a cache lookup could check if there is already a thumbnail for the given file.
    if not, return a standard icon and trigger an asynchronous creation of the thumbail and notify the view when it is ready.

    Cheers,
    _

  9. #9
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to preview of image in QFileDialog by default

    Quote Originally Posted by anda_skoa View Post
    Hmm.

    Another option might be a class derived from QFileSystemModel or a QIdentityProxyModel subclass on top of a normal QFileSystemModel.

    When an icon for a file (Qt:ecorationRole) is requested, a cache lookup could check if there is already a thumbnail for the given file.
    if not, return a standard icon and trigger an asynchronous creation of the thumbail and notify the view when it is ready.

    Cheers,
    _

    I try to create myFileSystemModel class, but I don't know how to load thumbnail from system

    I use QPixmapCache and use "fine" function, but it seem to be looking the cache from program, not system.

    so, if my program restart, the thumbnail will be reload,

    could you please give me more tips, thank you.

    this is my code:

    Qt Code:
    1. class cMyFileSystemModel : public QFileSystemModel{
    2. public:
    3. QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const{
    4. if(role == Qt::DecorationRole){
    5. QFileInfo fileInfo = this->fileInfo(index);
    6.  
    7. if( fileInfo.suffix().compare("jpg",Qt::CaseInsensitive)==0 ||
    8. fileInfo.suffix().compare("bmp",Qt::CaseInsensitive)==0 ||
    9. fileInfo.suffix().compare("png",Qt::CaseInsensitive)==0 ||
    10. fileInfo.suffix().compare("jpeg",Qt::CaseInsensitive)==0 )
    11. {
    12.  
    13. QPixmap pm;
    14. if (!QPixmapCache::find(fileInfo.filePath(), &pm)) {
    15.  
    16. pm.load(fileInfo.filePath());
    17. QPixmapCache::insert(fileInfo.filePath(), pm);
    18. QIcon myIcon(pm);
    19. return myIcon;
    20. }
    21.  
    22. }else{
    23. QIcon myIcon(pm);
    24. return myIcon;
    25. }
    26. }
    27.  
    28. }
    29. return QFileSystemModel::data(index,role);
    30. }
    31.  
    32. };
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to preview of image in QFileDialog by default

    Quote Originally Posted by yoll522 View Post
    I use QPixmapCache and use "fine" function, but it seem to be looking the cache from program, not system.
    I am not sure what you mean. "The QPixmapCache class provides an application-wide cache for pixmaps."

    Quote Originally Posted by yoll522 View Post
    so, if my program restart, the thumbnail will be reload,
    Your code doesn't show any persitance handling, i.e. no saving to disk or initializing the cache from disk.
    Maybe you forgot that and you are starting with an empty cache on each startup?

    Cheers,
    _

Similar Threads

  1. How can i have a QFileDialog with a preview of the picture?
    By Bong.Da.City in forum Qt Programming
    Replies: 10
    Last Post: 13th September 2016, 17:24
  2. QFileDialog set default name
    By Talei in forum Newbie
    Replies: 10
    Last Post: 24th March 2016, 02:10
  3. Preview Thumbnail of images in Custom QFileDialog
    By toglia3d in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2010, 22:54
  4. How set default file to save in QFileDialog
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 12:09
  5. QFileDialog::getSaveFileName default extension
    By elcuco in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2007, 20:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.