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. Select file OR directory?

Select file OR directory?

Scheduled Pinned Locked Moved General and Desktop
qfiledialog
9 Posts 3 Posters 5.0k 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.
  • M Offline
    M Offline
    Moschops
    wrote on 7 May 2015, 10:56 last edited by
    #1

    I need to allow the user to select a path; it could be a file OR a directory. Entirely up to the user. It looks like QFileDialog will allow the user to select a file, or a directory, but not either.

    That is, if I set it to allow the user to select a file they can't pick a directory, and vice-versa; I need to allow them to pick either a file, or a directory.

    Is there a way to do this with QFileDialog, or am I going to have to create a custom widget for this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 May 2015, 11:34 last edited by
      #2

      Hi,

      QFileDialog uses the native file dialog by default and that option it is not something that they provide (Not windows nor OS X at least). If you want that behavior, you'll have to go custom.

      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
      • M Offline
        M Offline
        mcosta
        wrote on 7 May 2015, 11:36 last edited by
        #3

        Hi,

        in which platform you have this issue?

        As you said QFileDialog is not able to select both files and directories.
        In our project (both for Windows and OS X) we have implemented this feature in OS X using native Objective-C API but we didn't found a way to do the same in Windows.

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        M 1 Reply Last reply 7 May 2015, 11:44
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 May 2015, 11:39 last edited by
          #4

          @mcosta this hack might interest you

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

          M 1 Reply Last reply 7 May 2015, 12:50
          0
          • M Offline
            M Offline
            Moschops
            wrote on 7 May 2015, 11:39 last edited by
            #5

            Thank you.

            Having had a hissy fit about it, I've decided that the best way to handle this is to go back up the line to the requirements monkeys and demand that they split out this particular requirement so I can identify cases that want a file, and cases that want a directory.

            Bad requirements are the root of so much trouble :)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 7 May 2015, 11:41 last edited by
              #6

              Wise decision

              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
              • M mcosta
                7 May 2015, 11:36

                Hi,

                in which platform you have this issue?

                As you said QFileDialog is not able to select both files and directories.
                In our project (both for Windows and OS X) we have implemented this feature in OS X using native Objective-C API but we didn't found a way to do the same in Windows.

                M Offline
                M Offline
                Moschops
                wrote on 7 May 2015, 11:44 last edited by
                #7

                @mcosta
                in which platform you have this issue?

                Linux, Windows and Solaris. We're surprisingly cross-platform.

                1 Reply Last reply
                0
                • S SGaist
                  7 May 2015, 11:39

                  @mcosta this hack might interest you

                  M Offline
                  M Offline
                  mcosta
                  wrote on 7 May 2015, 12:50 last edited by
                  #8

                  @SGaist said:

                  @mcosta this hack might interest you

                  is only a C# solution?

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 7 May 2015, 19:51 last edited by
                    #9

                    I forgot to double check but indeed it looks like that's the case

                    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

                    6/9

                    7 May 2015, 11:41

                    • Login

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