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. Escaping filter wildcard pattern in QFileDIalog
Qt 6.11 is out! See what's new in the release blog

Escaping filter wildcard pattern in QFileDIalog

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have an application with an export as action which opens up a native QFileDialog.
    Since I want it to be able to filter for image files, e.g. PNG I have the following constructor

    @QString filename = QFileDialog::getSaveFileName(this, "Save plot as", "", "PNG image ( *.png )");@

    As expected this shows in the filter selection menu the option "PNG image". However I would like it to also explicitly show the corresponding wildcard pattern i.e. "PNG image (*.png)"
    The naive attempt:

    @QString filename = QFileDialog::getSaveFileName(this, "Save plot as", "", "PNG image ( *.png )( *.png )");@

    because the regex in the filter parser stops on the first one. How would I go about escaping this to get a literal "(*.png)" in the filter name.

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      Hi and welcome to devnet.
      you can not have “PNG image (.png)” .
      but you can make a small change “PNG image [
      .png] (.png)” and pass it.
      then it will show PNG image [
      .png] .

      hope this helps.

      Be Cute

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks for your response. I had already considered that option but I would still prefer to use parentheses

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          What is shown in the dialog is platform dependent. e.g. on OS X, if you only have one filter, it's not even shown, however, if you have several, the text of the filter including the parentheses and pattern is shown

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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