Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom icons for QFileSystemModel
Qt 6.11 is out! See what's new in the release blog

Custom icons for QFileSystemModel

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi ,
    I was wondering if anybody knew of a way to use custom icons the file system uses to show your files/folders....The Doc has pointed me to QFileIconProvider but i did not find anyway to match "QFileIconProvider::IconType":http://qt-project.org/doc/qt-5.1/qtwidgets/qfileiconprovider.html#IconType-enum to the custom icons of my choosing.

    Any help would be appreciated.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      subclass QFileSystemModel and reimplement data() method. The following should do what you want:
      @
      QVariant MyFileModel::data ( const QModelIndex & index, int role ) const
      {
      if( index.column() == 0 && role == Qt::DecorationRole )
      //you may want to check "index.data().toString()" for the file-name/-extension
      return QVariant::fromValue(icon);
      else
      return QFileSystemModel::data(index, role);
      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        alternatively you can also subclass QFileIconProvider as you already mentioned and reimplement all virtual methods. And set the file icon provider class with QFileSystemModel::setIconProvider(yourIconProvider).

        [quote author="musimbate" date="1375257223"]Hi ,
        but i did not find anyway to match "QFileIconProvider::IconType":http://qt-project.org/doc/qt-5.1/qtwidgets/qfileiconprovider.html#IconType-enum to the custom icons of my choosing.[/quote]
        What exactly do you mean?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • musimbateM Offline
          musimbateM Offline
          musimbate
          wrote on last edited by
          #4

          Thanks raven-worx for the reply.

          [quote author="raven-worx" date="1375263368"]
          What exactly do you mean?
          [/quote]

          I thought I could use QFileInfoProvider to set the icons that QFileSystemModel uses to show the icons for files/folders.If this could be done there should be some kind of setIcon()/setIcons() function to set them right?

          May be I am getting wrong the intended usage of QFileInfoProvider.

          Why join the navy if you can be a pirate?-Steve Jobs

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            i haven't looked into the sources of QFileSystemModel yet, but i would bet that it queries the icon from the QFileIconProvider in it's data() method implementation for the decoration role. (In the way like i stated it in the code before)

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved