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

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
windowsfilebrowserfile dialogfilesystem
12 Posts 2 Posters 5.4k Views
  • 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.
  • A Offline
    A Offline
    AlexP11223
    wrote on last edited by AlexP11223
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A Offline
        A Offline
        AlexP11223
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlexP11223
            wrote on last edited by AlexP11223
            #5

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              How do you currently navigate them ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AlexP11223
                wrote on last edited by AlexP11223
                #7

                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.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  1
                  • SGaistS SGaist

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

                    A Offline
                    A Offline
                    AlexP11223
                    wrote on last edited by AlexP11223
                    #9

                    @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).

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

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

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • A Offline
                        A Offline
                        AlexP11223
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          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.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2

                          • Login

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