Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQT5 QFileDialog only works correctly when the file mode is set to 'Directory'
Forum Updated to NodeBB v4.3 + New Features

PyQT5 QFileDialog only works correctly when the file mode is set to 'Directory'

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 3 Posters 474 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.
  • R Offline
    R Offline
    randizzleDee
    wrote on last edited by
    #1

    The following code works as expected:

    dialog = QFileDialog(self)
    dialog.setFileMode(QFileDialog.Directory)
    if dialog.exec():
         save_folder = dialog.selectedFiles()
    

    However, changing the file mode and adding a filter causes the exec call to fail:

    image_dialog = QFileDialog(self)
    image_dialog.setFileMode(QFileDialog.ExistingFiles)
    image_dialog.setNameFilter("Images (*.png *.jpg *.pgm)")
    if image_dialog.exec():
          filename = image_dialog.selectedFiles()
    

    Any Idea why this might be the case? Both code snippets reside in the same slot function within the main window class, and this behavior seems to be consistent no matter where In the program I move them to.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      Well, if there are no existing files that match your filter then it would fail, right?

      I light my way forward with the fires of all the bridges I've burned behind me.

      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