Skip to content
Advertisement

How to filter executables using QFileDialog? (Cross-platform solution)

The documentation for QFileDialog.getOpenFileName does not provide any clue on how to filter only executables using a const QString &filter = QString(). Here’s the code for my action using PyQt5:

JavaScript

On linux, naturally, I have no file extensions for executables, but I need to filter .exe extensions on windows (Which I intend to provide a version for). Also, there’s no overloaded method that allows QDir::Executable. How can I use QFileDialog.getOpenFileName while filtering only executables, no matter which platform it’s running on?

Advertisement

Answer

If you want a more personalized filter then you have to use a proxyModel but for this you cannot use the getOpenFileName method since the QFileDialog instance is not easily accessible since it is a static method.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement