Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Select file OR directory?

    General and Desktop
    qfiledialog
    3
    9
    3846
    Loading More Posts
    • 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
      Moschops last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • M
          mcosta last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            @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 Reply Quote 0
            • M
              Moschops last edited by

              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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • M
                  Moschops @mcosta last edited by

                  @mcosta
                  in which platform you have this issue?

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

                  1 Reply Last reply Reply Quote 0
                  • M
                    mcosta @SGaist last edited by

                    @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 Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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 Reply Quote 0
                      • First post
                        Last post