The original question was mainly related to the new way PyQt6 uses Enums, which now always require the full namespace: until PyQt5, the syntax Class.FlagName
was sufficient, but PyQt6 now requires Class.EnumName.FlagName
.
The other issue is probably related to QTBUG-88709 and is part of a long series of issues that deal with native dialogs provided by the OS, which always depend on the system.
There is no direct solution for this, and the only safe way is to enforce the DontUseNativeDialog
flag whenever in doubt:
dir_path = QFileDialog.getExistingDirectory(
parent=self,
caption="Select directory",
directory=HOME_PATH,
options=QFileDialog.Option.DontUseNativeDialog,
)
Note that:
- the
ShowDirsOnly
is useless as it's always set whenever the file dialog is in Directory
mode (which is automatically done for the getExistingDirectory()
static function);
- using the non-native dialog will obviously be inconsistent with the normal dialog shown by the OS;
- it is unclear if the bug was automatically resolved in Ubuntu/Gnome versions following the environment normally used in Ubuntu 20.04;
- there is no direct way to enforce the workaround only when required: either you find out the specific cause of the issue, or you just assume it doesn't work and always use the non-native dialog;