Is it possible to add custom/fake drives to QFileDialog?



  • I am using non-native QFileDialog (for choosing directory path) in my Windows-only app and I need to add some custom drives. I don't even need to display any content inside of these drives for now, I just need to display these drives on the top level (and preferably with my icon) and output some special string in the result when user selects it.

    enter image description here

    What is the easiest way to do this? Is it possible without implementing my own file dialog from scratch?

    I have read in the documentation that proxy model can be used "if you want to modify the underlying model; for example, to add columns, filter data or add drives", but I don't understand how to implement such model, all examples show only filtering and sorting of the already available items.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The idea would be that you'd "shift" the orignal model from the number of drives you want to add and when your model is requested for the values below that shift value, you return what you want and otherwise the original model data.



  • In which method I can return it? data? Or there is a better alternative where I can just create an item (QFileSystemModel?) without handling output for all its fields?


  • Lifetime Qt Champion

    You'll have to implement data, setData, rowCount.

    What exactly do you want to do with these additional drives ?



  • It will be mobile devices (MTP).

    Unfortunately even Windows Explorer/native dialog does not expose them as full fledged drives: they can be navigated, but they do not have path/"letter", it is not possible to choose them in file dialog, refer via string path, etc. Only via separate WPD API.


  • Lifetime Qt Champion

    How do you currently navigate them ?



  • What do you mean? Navigate where?
    It's not implemented yet.

    I can load the list of devices via API, and I wanted to add them to the file dialog and when user chooses the device return some kind of special string containing its ID instead of normal path.


  • Lifetime Qt Champion

    @AlexP11223 said in Is it possible to add custom/fake drives to QFileDialog?:

    Unfortunately even Windows Explorer/native dialog does not expose them as full fledged drives: they can be navigated, but they do not have path/"letter".

    You wrote it yourself, hence I asked how you would navigate them currently.

    In that case, my suggestion still stands, in your proxy model, use these API to gather information about these devices and add these entries to the top or bottom and shift the original model accordingly.



  • @SGaist said in Is it possible to add custom/fake drives to QFileDialog?:

    You wrote it yourself, hence I asked how you would navigate them currently.

    The same as normal Windows drives, except that they don't have path and cannot be chosen (in native file dialog).


  • Lifetime Qt Champion

    I meant, how are you doing it currently ? Do you already wrote some code that allows that ?



  • This functionality is not implemented in my app yet (except library with non-UI stuff like working with mobile devices via WPD API).

    It is possible to simply show a list of mobile devices in combobox, but it would make UI much more complicated, so it was decided that device selection should be done in the same dialog as for directory selection.


  • Lifetime Qt Champion

    Then, AFAUI, you have all what you need to continue. If implementing the proxy model looks daunting start by just a custom QAbstractItemModel with a QListView and once you have what you want you can go with the proxy and the shifting I suggested before.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.