QFileDialog on different platforms
-
Hi Forum
Asking some help here doing some multiplatform work. I have a pretty simple and straight forward open method opening some files. It works great and compiles on all platforms. On macOS (both Intel/Silicon) the filter for the filename suffix makes the filtered out files "grayed out" than than not showing them.
Is there a way around this? I do not like sifting through grayed-out files when I applied a filer to show only, for example, .pro-files. Works perfectly on Windows (PC), Linux (PC), Raspberry PI, Haiku/BeOS (PC) but not on macOS (Intel/Apple Silicon). Any suggestions or is it something I have to live with a MacOS?QT 6.9.1 on PC, QT 5 somthing on Raspberry, QT 6.91 on both Mac
void MceBaseEditor::openFile()
{
QString startDir = getUserHomePath();
if (!lastOpenFilePath.isEmpty()) {
QFileInfo info(lastOpenFilePath);
if (info.exists() && info.isDir()) {
startDir = lastOpenFilePath;
}
}QString fileName = QFileDialog::getOpenFileName( this, "Open File", startDir, "C/C++/CS Files (*.c *.cpp *.cc *.cxx *.cs *.h *.hpp *.hh *.hxx);;" "Pascal Files (*.pas *.pp);;" "Python Files (*.py);;" "Ada Files (*.ada *.adb *.ads);;" "Qt Project Files (*.pro);;" "Text and Markup Files (*.txt *.json *.xml *.md);;" "All Files (*.*)" ); if (!fileName.isEmpty()) { openFile(fileName); } updateFileActions();
}
Regards /Patrik
-
I believe is is because by default the file open dialog uses the "OS native" file dialog of the system on which is running. I'm not a MAC person but is that the default MAC behaviour? I also thought there was a way to disable (a switch) to tell the framework to not use the native OS dialogs, but I haven't messed with that stuff in ages so I cannot tell you quickly what it was, or even if I was hallucinating.
-
I believe is is because by default the file open dialog uses the "OS native" file dialog of the system on which is running. I'm not a MAC person but is that the default MAC behaviour? I also thought there was a way to disable (a switch) to tell the framework to not use the native OS dialogs, but I haven't messed with that stuff in ages so I cannot tell you quickly what it was, or even if I was hallucinating.
@Kent-Dorfman said in QFileDialog on different platforms:
I also thought there was a way to disable (a switch) to tell the framework to not use the native OS dialogs, but I haven't messed with that stuff in ages so I cannot tell you quickly what it was, or even if I was hallucinating.
Yes, there is
QFileDialog::DontUseNativeDialog
inQFileDialog::Options
, or the globalQt::AA_DontUseNativeDialogs
application attribute.
But OP must be noted that this uses Qt's own ui and looks far way different from the native file dialogs.Also from the doc of Qt5 there's a note above this option, not sure what it means as I don't have a MAC system
Note: This option is not supported on macOS when using the native file dialog.