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 in directory browser?
Qt 6.11 is out! See what's new in the release blog

Custom icons in directory browser?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I'm using a standard QFileDialog to let the user specify a directory. For this particular use case, the user must be able to traverse the directory tree as normal, but ultimately only certain directories are valid choices. These valid directories can be identified functionally; it would be ideal if I could change the icon of these directories so the user can easily see which directories are a valid choice.

    Is there a way to dictate at runtime the icon used for each directory, based on the results of a function? I had a root around in QFileDialog but didn't see anything.

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

      yes it is possible, but only if you use QFileDialog without the static members, meaning you don't use the native file dialogs.

      For this you need to implement you custom "QFileIconProvider":http://qt-project.org/doc/qt-4.8/qfileiconprovider.html and "set it to the QFileDialog":http://qt-project.org/doc/qt-4.8/qfiledialog.html#setIconProvider.

      You need to reimplement QFileIconProvider::icon() (i'm not sure which one of the both are called, just test it). Probably the best would be to take icon from the base class (which QFileIconProvider gives you), get the QPixmaps out of the QIcon and paint your stuff on them and add them to a new QIcon which you return.

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