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. QFileDialog and Filters
Qt 6.11 is out! See what's new in the release blog

QFileDialog and Filters

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 798 Views 1 Watching
  • 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    What is the defined behaviour of QFileDialog if the user has called setNameFilters() with a set of filters, but has not called selectNameFilter()?

    If this were the Windows CFileDialog, the behaviour in this case is determined by the value of nFilterIndex in the OPENFILENAME struct:

    nFilterIndex

    Type: DWORD

    The index of the currently selected filter in the File Types control. The buffer pointed to by lpstrFilter contains pairs of strings that define the filters. The first pair of strings has an index value of 1, the second pair 2, and so on. An index of zero indicates the custom filter specified by lpstrCustomFilter. You can specify an index on input to indicate the initial filter description and filter pattern for the dialog box. When the user selects a file, nFilterIndex returns the index of the currently displayed filter. If nFilterIndex is zero and lpstrCustomFilter is NULL, the system uses the first filter in the lpstrFilter buffer. If all three members are zero or NULL, the system does not use any filters and does not show any files in the file list control of the dialog box.

    Thanks
    David

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Simply look at the source code :)

      https://code.woboq.org/qt5/qtbase/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp.html#_ZNK26QWindowsXpNativeFileDialog20populateOpenFileNameEPii

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        Actually what I really want to know is what it is supposed to do in this scenario for all operating systems.

        I know that on Windows, if the user hasn't selected the filter, it will use the first filter that the user has defined, is that consistently true for all systems?

        Thanks
        David

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Perdrix said in QFileDialog and Filters:

          is that consistently true for all systems?

          You have to ask the OS vendors I would guess (or better the window-manager vendors)

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #5

            I'm asking about the behaviour of QFileDailog so the question belongs here IMHO.

            D.

            Christian EhrlicherC JonBJ 2 Replies Last reply
            0
            • PerdrixP Perdrix

              I'm asking about the behaviour of QFileDailog so the question belongs here IMHO.

              D.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Perdrix Then take a look at the sources.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • PerdrixP Perdrix

                I'm asking about the behaviour of QFileDailog so the question belongs here IMHO.

                D.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @Perdrix
                The usual rule is: if the Qt docs do not state explicitly what such-and-such a behaviour is, then there isn't a "defined/guaranteed" behaviour. Else the docs would have said so!

                People then look at the source code if they want to know what is really going on. And you're welcome to do that. It quite possibly will not change from however you see it now, but that is not a promise, so you act on it at your own risk.

                1 Reply Last reply
                2

                • Login

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