Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67993

QFileDialog Save dialog: need more control over filename

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.10.0, 5.11.0 Beta 4
    • None
    • Initially observed on Arch Linux (KDE Plasma 5.12.4), but it also applies to macOS. (And probably to Windows using the non-native dialog as well.)

    • Linux/X11, macOS, Windows

    Description

      The non-native Save file dialog currently provides little control over the filename. Issues:

      • It always changes everything after the last ., replacing it whenever the file filter type changes.
      • The selected file extension is the first in the filter list (probably fine, but this is not documented).
      • Extensions with multiple parts (*.tar.gz) are not supported. If a file foo.pcap was selected, then this will change the name into foo.gz.
      • The reason a non-native dialog was used is to add an additional checkbox for compressing files. Enabling the option should assume the .gz suffix if missing. It is currently not possible to add this unless it is listed as first item in the filter.
      • macOS (tested with TextEdit) has a checkbox "Hide extension", unchecking this allows you to remove the extension. Windows (tested with Notepad) makes it possible to ignore the extension from the filetype by quoting the filename. Qt provides defaultSuffix which allows the programmer to control behavior, but otherwise it does not change the filename.

      Proposal:

      • Only replace the file suffix if it does not match any of the listed extensions (in all filters). Append in other cases, even if there are periods, consider for example 2018.04.27 - photo, that should become 2018.04.27 - photo.jpg and not 2018.04.jpg.
        • Note that GIMP (GTK+?) differs when no extension matches: it will replace the last suffix anyway rather than appending stuff.
      • Something that makes it possible to implement the above .gz extension option. Some ideas:
        • A mechanism to control the filename based on fileSelected or an external trigger/signal. It could be a virtual function that acts as a filter on a the current filename (not file path). The default implementation could change the suffix as described above.
        • When a dialog is open, allow setNameFilters or setNameFilters to change the current filter and behavior. Then the developer can invoke selectFile to append or remove .gz from the current name. And using a filter name such as *.pcap.gz *.pcap, changes to the file filter will choose .pcap.gz rather than .pcap.
      • Related to this: the current "default extension" is not flexible. Either there is none, or there is a fixed one which is only applied if the file path has no dot (QTBUG-59401). Using the same filename filter above, it would be much easier to force a filename and ensure that the user is prompted if a file already exists.

      Workarounds that I currently use:

      • Set an empty initial suffix (My type (. *.pcap.gz *.pcap)). Since the extension rewrite only occurs if the first suffix has a non-empty part after the dot, this nicely prevents the broken rewriting from happening.
      • Override QFileDialog::accept to call selectFile with a fixed up filename. Limitation: this only works when the filename box is not focused. Workaround: call QFileDialog::setFocus to remove focus from the filename box.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Lekensteyn Peter Wu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes