Results 1 to 5 of 5

Thread: How to get file type Icon ?

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default How to get file type Icon ?

    So far, I get icon file like this

    Qt Code:
    1. QIcon Olongia::fileIcon(const QString &filename)
    2. {
    3. QFileInfo info(filename);
    4. const QString ext=info.suffix().toLower();
    5.  
    6. QIcon icon;
    7. if (ext == "pdf") {
    8. icon=QIcon::fromTheme("application-pdf");
    9. } else if (ext.startsWith("doc")) {
    10. icon=QIcon::fromTheme("application-msword");
    11. } else if (ext=="zip" ||
    12. ext=="gz" ||
    13. ext=="bz2" ) {
    14. icon=QIcon::fromTheme("application-x-archive");
    15. } else if (ext=="png" ||
    16. ext=="jpg" ||
    17. ext=="gif" ||
    18. ext=="svg" ||
    19. ext=="bmp") {
    20. icon=QIcon::fromTheme("image-x-generic");
    21. } else {
    22. QProxyStyle s;
    23. icon=s.standardIcon (QStyle::SP_FileIcon);
    24. }
    25.  
    26. return icon;
    27. }
    To copy to clipboard, switch view to plain text mode 

    I think that is not efficient, and after read qtdoc I get new trick like this

    Qt Code:
    1. QFileInfo info(filename);
    2. QIcon icon=ip.icon(info);
    To copy to clipboard, switch view to plain text mode 

    But, that code only working if file is exists in local system. And I need get file type icon for file not exists in local system ? Like QFtp example, only get the filename and show in the TreeViewWidget ?

    Thank's before and sorry about my suck english

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get file type Icon ?

    You can create temporary empty file with wanted extention and go with way, you described

  3. #3
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: How to get file type Icon ?

    Nice idea. I will try

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get file type Icon ?

    How about taking a look at the source code of QFileIconProvider to see how it does it and do the same without having a real file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: How to get file type Icon ?

    Quote Originally Posted by borisbn View Post
    You can create temporary empty file with wanted extention and go with way, you described
    This trick work on GNOME and Windows. But not on KDE

Similar Threads

  1. Replies: 0
    Last Post: 17th March 2010, 13:25
  2. How to know file type
    By nrabara in forum Newbie
    Replies: 2
    Last Post: 16th December 2009, 13:30
  3. Replies: 5
    Last Post: 5th August 2009, 17:32
  4. change txt file type default icon
    By mismael85 in forum Qt Programming
    Replies: 8
    Last Post: 20th February 2008, 22:22
  5. Associating icon with a file type
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2006, 16:57

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.