Escaping filter wildcard pattern in QFileDIalog



  • 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.



  • 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.



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


  • Lifetime Qt Champion

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.