Is it possible to add custom/fake drives to QFileDialog?
-
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? -
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.
-
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.
-
@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).
-
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. -
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.