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 prevent user from overriding file filter
Forum Updated to NodeBB v4.3 + New Features

QFileDialog prevent user from overriding file filter

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 451 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.
  • D Offline
    D Offline
    Dimi
    wrote on 7 Jan 2022, 12:41 last edited by Dimi 1 Jul 2022, 12:43
    #1

    I have a QFileDialog used like:

    fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
    

    This filters and shows only image files which is all good and nice. However, the user is still allowed to override this by typing "*" in the filename field and pressing enter. By looking at the documentation there isn't a suitable signal I can connect to and filter or deny that input. Any suggestions how to prevent the user from overriding the file filter and showing other non image files?

    J F 2 Replies Last reply 7 Jan 2022, 12:57
    0
    • D Dimi
      7 Jan 2022, 12:41

      I have a QFileDialog used like:

      fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
      

      This filters and shows only image files which is all good and nice. However, the user is still allowed to override this by typing "*" in the filename field and pressing enter. By looking at the documentation there isn't a suitable signal I can connect to and filter or deny that input. Any suggestions how to prevent the user from overriding the file filter and showing other non image files?

      J Online
      J Online
      JonB
      wrote on 7 Jan 2022, 12:57 last edited by JonB 1 Jul 2022, 12:58
      #2

      @Dimi
      QFileDialog::filterSelected(const QString &filter) might? But may only be if user selects a filter, not types into field, I don't know? You would have to use a QFileDialog instance to use that.

      Really you mostly want to check the returned filename for acceptability rather than worrying about what filter the user may or may not use.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dimi
        wrote on 7 Jan 2022, 13:39 last edited by
        #3

        Instancing QFileDialog or creating my own is not a problem. I tried all signals and filterSelected is when a user selects a filter, not types (as you suspected). I was just wondering if there's any way not to show at any file types that shouldn't be accepted. Checking the output afterwards is a good enough solution. Thank you for the suggestion!

        1 Reply Last reply
        1
        • D Dimi
          7 Jan 2022, 12:41

          I have a QFileDialog used like:

          fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
          

          This filters and shows only image files which is all good and nice. However, the user is still allowed to override this by typing "*" in the filename field and pressing enter. By looking at the documentation there isn't a suitable signal I can connect to and filter or deny that input. Any suggestions how to prevent the user from overriding the file filter and showing other non image files?

          F Offline
          F Offline
          fadu
          wrote on 7 Jan 2022, 16:31 last edited by
          #4

          @Dimi you can check file after open file dialog finished
          If file end with.jpg .png etc....

          1 Reply Last reply
          0

          1/4

          7 Jan 2022, 12:41

          • Login

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