Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jul 2019
    Posts
    1
    Qt products
    Platforms
    Unix/X11

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

    The following code works as expected:
    Qt Code:
    1. dialog = QFileDialog(self)
    2. dialog.setFileMode(QFileDialog.Directory)
    3. if dialog.exec():
    4. save_folder = dialog.selectedFiles()
    To copy to clipboard, switch view to plain text mode 
    However, changing the file mode and adding a filter causes the exec call to fail:

    Qt Code:
    1. image_dialog = QFileDialog(self)
    2. image_dialog.setFileMode(QFileDialog.ExistingFiles)
    3. image_dialog.setNameFilter("Images (*.png *.jpg *.pgm)")
    4. if image_dialog.exec():
    5. filename = image_dialog.selectedFiles()
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    That looks like it should work.

    Have you tried narrowing it down to either the filter or the different mode?

    Also you might want to check if the Python API offers the same static convenience functions the C++ API has.
    QFileDialog::getOpenFileName() is much more straight forward to use.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2014, 10:03
  2. Replies: 2
    Last Post: 4th June 2012, 12:56
  3. QFiledialog directory of selected file
    By seifhatem in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2011, 20:05
  4. QFileDialog selecting file or directory
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 20th June 2008, 09:28
  5. Replies: 4
    Last Post: 13th June 2007, 15:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.