Qt Forum

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

    Unsolved QFileDialog: choose directories only but show files as well

    General and Desktop
    qfiledialog qdir
    3
    13
    21379
    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
      michelson last edited by

      Hello,
      I would like to have aQFileDialog from which i will be able to choose dirs but meanwhile i should be able to see files in them as well. I tired:
      QString path = QFileDialog::getExistingDirectory(this, tr("Choose catalog"), ".", QFileDialog::ReadOnly);
      I can choose dirs and thats ok but i cant see any files, any help?

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        hi
        And
        QFileDialog::getOpenFileName();
        is not what you want?
        It's a normal file open?

        1 Reply Last reply Reply Quote 0
        • M
          michelson last edited by michelson

          I want to pick dirs ONLY (so the result of if would be the path to the DIR), but able to see files as well. Like you want to choose DIR to read all files of some type from but you want to be able to see the files as well so you know you pick correct folder. So getOpenFileName() doesnt suites here exatcly (or i customize it wrong...).

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @michelson last edited by

            @michelson
            Ok. I understand.
            Not sure how you can make it show the files but only
            allow to press ok on folder. Not in any easy way.

            It is not an option to let the user also select a file and just snag the path from it ?

            1 Reply Last reply Reply Quote 0
            • M
              michelson last edited by

              You know, i CAN do that (i mean its just home-use app so its not a big deal it wont work as i want) but for the sake of good-looks of a whole project i wanted to at least try to implement this one thing :D

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @michelson last edited by

                @michelson
                Well there is a lot of flags. But there is not one that sounds like such function.
                (in my head)
                You could make your own dialog but that
                somewhat a lot of work to NOT select a file.

                You could also make it 2 step.
                First select folder
                Then dialog comes with all files , each checked and u can exclude some if needed
                or else press ok to proceed.
                That way is 100% want you want and serves a function.

                1 Reply Last reply Reply Quote 0
                • Hamed.Masafi
                  Hamed.Masafi last edited by

                  QFileDialog dialog;
                  dialog.setFileMode(QFileDialog::DirectoryOnly);
                  dialog.setOption(QFileDialog::ShowDirsOnly, false);
                  dialog.exec();
                  qDebug() << dialog.directory();
                  

                  Remote object sharing (OO RPC)
                  http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                  Advanced, Powerful and easy to use ORM for Qt5
                  https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @Hamed.Masafi last edited by

                    @Hamed.Masafi
                    Hi
                    it looks good but its not showing files here on win 7.
                    Only the dirs.
                    On your platform, it does show all files also?

                    Hamed.Masafi 1 Reply Last reply Reply Quote 0
                    • Hamed.Masafi
                      Hamed.Masafi @mrjj last edited by Hamed.Masafi

                      @mrjj said:

                      Hi
                      it looks good but its not showing files here on win 7.
                      Only the dirs.
                      On your platform, it does show all files also?

                      Hi, on my platform (debian + kde) works well. But we can take a test.
                      Please change second line to flowing code and test again.

                      dialog.setFileMode(QFileDialog::Directory);
                      

                      Remote object sharing (OO RPC)
                      http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                      Advanced, Powerful and easy to use ORM for Qt5
                      https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                      mrjj 1 Reply Last reply Reply Quote 0
                      • mrjj
                        mrjj Lifetime Qt Champion @Hamed.Masafi last edited by

                        @Hamed.Masafi
                        Ok, must be different on win
                        Hmm am i blind or is that same line?

                        1 Reply Last reply Reply Quote 0
                        • Hamed.Masafi
                          Hamed.Masafi last edited by

                          Oh, sorry. My mistake

                          dialog.setFileMode(QFileDialog::Directory);
                          

                          Remote object sharing (OO RPC)
                          http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                          Advanced, Powerful and easy to use ORM for Qt5
                          https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                          1 Reply Last reply Reply Quote 0
                          • M
                            michelson last edited by

                            @Hamed.Masafi
                            Unfortunetly i can confirm @mrjj issiue - Win7 OS still couses files to be invisible. I guess problem cant be solved easily @ Win OS - i think the only way is to reimplement QFileDialog which for me is just not worth the time it will take for such trivial thing.

                            1 Reply Last reply Reply Quote 0
                            • Hamed.Masafi
                              Hamed.Masafi last edited by

                              I've tested on windows. It seems the only possible solution is to ignore native dialog.

                              QFileDialog dialog;
                              dialog.setFileMode(QFileDialog::DirectoryOnly);
                              dialog.setOption(QFileDialog::DontUseNativeDialog, true);
                              dialog.setOption(QFileDialog::ShowDirsOnly, false);
                              dialog.exec();
                              qDebug() << dialog.directory();
                              

                              Remote object sharing (OO RPC)
                              http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                              Advanced, Powerful and easy to use ORM for Qt5
                              https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                              1 Reply Last reply Reply Quote 1
                              • First post
                                Last post