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. Using QFileDialog to select a project directory
QtWS25 Last Chance

Using QFileDialog to select a project directory

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 11.7k 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.
  • S Offline
    S Offline
    steveicarus
    wrote on last edited by
    #1

    I'm working on an application that keeps project information in a directory, instead of a simple file. This directory name has the suffix ".iab". Is it possible to convince a QFileDialog to constrain users to selecting directories with .iab suffix?

    An example: If a user is looking for the project "foo", I would like to set the name filter to *.iab and have the user browse around for the "file" foo.iab. This file is actually implemented as a directory, but I want the file browser to present *.iab files as the goal.

    I've made a go at it, but it's not working consistently. On Mac OS X I setFilter(QDir::Dirs) and setNameFilter("Icarus Astrobench Project (*.iab)"), and it sorta works. But on Linux, it seems to be impossible to select that directory unless I add setFileMode(QFileDialog::Directory).

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #2

      from the "docs":http://doc.qt.nokia.com/4.7/qfiledialog.html:
      @
      fileName = QFileDialog::getOpenFileName(this,
      tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
      @

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

        vinb: are you sure that also works for selecting directories?

        steveicarus: if you want to select a directory, doesn't it make sense to use a mode for QFileDialog that is actually geared to do that? Why is it a problem to use setFileMode(QFileDialog::Directory)?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vinb
          wrote on last edited by
          #4

          @Andre: ehm.. :) my mistake, didnt read the question properly. Thanks for pointing that out in a subtle way.

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

            [quote author="vinb" date="1303817850"]@Andre: ehm.. :) my mistake, didnt read the question properly. Thanks for pointing that out in a subtle way.
            [/quote]
            Happens to me too :-)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              steveicarus
              wrote on last edited by
              #6

              When I use:
              @setFileMode(QFileDialog::Directory)
              setNameFilter("... (*.iab)")@
              and try it on Mac OS X, the foo.iab selections are grayed out and any directories except foo.iab are selectable; exactly opposite what I want: I only want to select directories named foo.iab. It's closer when I do not setFileMode to Directory. Apparently, the setNameFilter takes precedence there.

              But on Linux, I cannot select any directories, not even foo.iab, unless the QFileDialog::Directory mode is set, but then on Linux the setNameFilter filter is ignored for directories. The experience is not quite right.

              I guess what I really want is for the QFileDialog to pretend that foo.iab directories are bundles, and I need it to work on Mac OS X and Linux. I'm OK with deriving from QFileDialog to implement more complex selection criteria, if that's what it takes.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vinb
                wrote on last edited by
                #7

                You can also add the option QFileDialog::ShowDirsOnly.

                1 Reply Last reply
                0

                • Login

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