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 476 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 last edited by Dimi
    #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?

    JonBJ faduF 2 Replies Last reply
    0
    • D Dimi

      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?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #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 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

          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?

          faduF Offline
          faduF Offline
          fadu
          wrote on 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

          • Login

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