Qt Forum

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

    QFileDialog

    General and Desktop
    4
    8
    4915
    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.
    • F
      Felix last edited by

      Hi,

      I need the user to select either one folder or one file with a specific extension. Since the FileMode of QFileDialog is not a QFLag, i cant set FileMode (ExistingFile | Directory).

      Is there any trick or workaround to solve my problem?

      Thanks

      Felix

      1 Reply Last reply Reply Quote 0
      • E
        erapid last edited by

        http://www.qtcentre.org/threads/4810-QFileDialog-how-to-choice-File-or-Directory-in-the-same-Dialog

        In short, the only solution - write your own dialog. In discussing the details are correct: "It would be hard to create a combined directory and file dialog. Much because it would be impossible to tell if you pick a directory or just want so enter it to look for other directories or files."

        QFileDialog has only one button that which takes one of two states: Open (dir) | Select. But you need two buttons in the same time.

        1 Reply Last reply Reply Quote 0
        • L
          lyuts last edited by

          I think that you don't need to do that. Just
          @setFileMode(QFileDialog::Directory)@.
          Looks like this should be enough because the description for this flag says
          bq. The name of a directory. Both files and directories are displayed. eq.

          I'm a rebel in the S.D.G.

          1 Reply Last reply Reply Quote 0
          • E
            erapid last edited by

            That's right, displays directories and files. But you can select only directories :) That said, the problem of an only one button

            1 Reply Last reply Reply Quote 0
            • L
              lyuts last edited by

              Oh, I see. Well, the first that comes to mind is to create a widget which contains a button (or radio button group) and a file dialog. A click on a button changes the fileMode() from Directory to ExistingFile and vice versa. I'm not sure this will look great in terms of UI, but I don't see any other easy solution.

              I'm a rebel in the S.D.G.

              1 Reply Last reply Reply Quote 0
              • F
                Felix last edited by

                i think i a desktop application, having radiobuttons like that to choose a dialog is a bad solution. Also in my case the user neednt to know if it is a folder or a file, since it doesnt matter at all.

                1 Reply Last reply Reply Quote 0
                • L
                  lyuts last edited by

                  It was just an idea, I'm not forcing you to follow it :).

                  I'm a rebel in the S.D.G.

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

                    I just run into a similar problem where the user needs to choose a directory or a file from a File Dialog
                    Here's my hack to solve it.

                    subclass your class from QFileDialog and set the FileMode to AnyFile
                    @

                    QFileSystemModel *model = new QFileSystemModel;
                    model->setRootPath(QDir::currentPath());
                    QStringList filenames;
                    QList<QUrl> urls;
                    urls << QUrl::fromLocalFile&#40;QDesktopServices::storageLocation(QDesktopServices::DesktopLocation&#41;&#41;
                         << QUrl::fromLocalFile&#40;QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation&#41;&#41;;
                    mfiledialog->setSidebarUrls(urls);
                    mfiledialog->setFileMode(QFileDialog::AnyFile);
                    mfiledialog->setViewMode(QFileDialog::Detail);
                    

                    Then have a slot to change FileMode on currentchanged signal as follows

                    void MainWindow::on_mfiledialog_currentchanged(QString filedir)
                    {
                    QFileInfo finfo = QFileInfo(filedir);
                    if(finfo.isDir())
                    mfiledialog->setFileMode(QFileDialog::Directory);
                    else
                    mfiledialog->setFileMode(QFileDialog::AnyFile);
                    }
                    @

                    Edit: please put @ tags around code sections; Andre

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