QfileDialog not using native dialogs on KDE Plasma 5.18
-
I opened this issue on the bug tracker, but as it is really blocking a lot of my users (that will soon be in a class context), I would like to know if anyone is reproducing it or if anyone has a workaround.
Just launch Qt examples related to file dialogs in a fresh Kubuntu 20.04
Thank you !
-
Hi,
Even if it looks trivial, can you provide a minimal compilable example on your bug report ?
This will ensure that everybody uses the same code to reproduce and debug your issue. -
Done. I'm not sure of the category I should have mentioned. I feel like "Widgets: Widgets and dialogs" is not looked at
#include <QApplication> #include <QFileDialog> int main(int argc, char *argv[]) { QApplication app(argc, argv); QFileDialog::getOpenFileName(); return app.exec(); }
-
@kamui
You may (well) know better than I, but why do you expect this to use native dialog? https://doc.qt.io/qt-5/qfiledialog.html#getOpenFileNamesOn Windows, and macOS, this static function will use the native file dialog and not a QFileDialog.
That implies to me that under Linux it (this
static
function) will use the Qt-non-native dialog? Unless you know better. In which case you would need to use one of the instance methods and setQFileDialog::DontUseNativeDialog
? Or did this used to work for you previously? -
@JonB I supposed the default behavior should be the same on every linux-based OS, and I have the same code opening native dialogs on Ubuntu 20.04 with Gnome.
I tried the following code, no changes :
#include <QApplication> #include <QFileDialog> int main(int argc, char *argv[]) { QApplication app(argc, argv); QFileDialog dialog; dialog.setOption(QFileDialog::DontUseNativeDialog, false); dialog.exec(); return app.exec(); }
when false :
when true :
-
@kamui said in QfileDialog not using native dialogs on KDE Plasma 5.18:
be the same on every linux-based OS
When Qt docs state "On Windows, and macOS", they mean/imply not Linux! But you have tested what I suggested now.... And I agree it works on Ubuntu + GNOME.
-
With an application of mine built using Qt 5.12 on Ubuntu 18.04 and GTK/Gnome, I used to get the native file dialogs all the time. Actually, I reported a bug with the file filter rendering related to this: https://bugreports.qt.io/browse/QTBUG-78557
Now when I build the same code on Ubuntu 18.04 but using Qt 5.15.5, I cannot get Qt to use the native dialogs. This is complicated because it messes up my work-around using fake parentheses Unicode characters in the file filters to keep them from being truncated.
Besides, I like the
nautilus
file browser much better than what I am seeing now.I did a quick comparison of the source code in
qfiledialog.cpp
between Qt 5.12.12 and 5.15.5, but there were only some minor differences such as replacing literal"0"
withnullptr
where pointers are concerned, and the newargs
implementation. There must be something else deeper down that prevents using native file dialogs? -
@JonB In the documentation for Qt 5.15 for
QFileDialog
, there is also this:By default, a platform-native file dialog will be used if the platform has one...
This can be found in a browser by hitting CTRL-F and searching for "native". It seems that Ubuntu 18.04/GTK in fact DOES have native dialogs because they were still used in Qt 5.12.9 (AFAICT).
-
Following up to this, it appears that the GTK3 plugins are not built with Qt 5.15.5 unless the version of GTK3 is 3.6 or greater. On Ubuntu 18.04, I have version 3.0 according to pkg-config. So, following the work-around on the bugreport forum, I added the lines
export QT_PLATFORMTHEME=gtk3 export QT_QPA_PLATFORMTHEME=gtk3
to my
.bashrc
file. This had no effect. Started my app from the command-line with the option--platformtheme=gtk3
-- also no good.Seems like Qt 5.12 was less picky about this? I will try to upgrade my
gtk3
if possible. -
Hi, had to resurrect this topic after 2 years as I have encountered the exact same issue that drove me crazy for several days with many different version of Qt source compilation.
Basic system info:
- Debian 12
- KDE Plasma 5.27.5
- KDE Framework 5.104.0
- KDE based on Qt 5.15.8
- Qt Creator 5.0.3 (based on Qt 5.15.2)
- Qt 5.15.8 toolkit compiled from source.
I have an app compiled year ago with earlier version of KDE or different distro i think (can't recall), which uses a nice File Open dialog (pic #1), but when I recompile it again with my current system it always use a FileOpen dialog (pic #2) which is much simpler and not as good-looking as before.
Tried play with 'DontUseNativeDialog' option in QFileDialog but nothing changed.
I would really like to get that beautiful FileOpen dialog (pic #1) back, Anyone has clue?
Pic #1 (preferred):
Pic #2:
-
UPDATE:
I fresh installed a KDE Neon system.- KDE Neon
- KDE Plasma 6.1.4
- KDE Framework 6.5.0
- KDE based on Qt 6.7.2
I re-run my app (built on Qt 5.15.8) to open a file dialog, it opens with nice file open dialog. Nothing changed, not -recompiled. This makes me think the inconsistence was due to KDE system (Framework maybe?)
Any thoughts?
-
Conclusion & Solutions
Conclusion:
System Qt Library or Plugin path mixed up with Qt Creator enforced Qt Library or Plugin path.
We need to enforce our app to use system Qt library or plugin path, not Qt build library or path.This can be evidenced by:
- Rename Qt development or Qt custom build library path, so that our app will be forced to look and use system available Qt library or plugin.
- Uninstall Qt Creator, so that Qt toolkit library will be also removed (or path reference become invalid) and our app will only use system Qt libraries and plugins.
Solutions:
- Use a bash script to wrap our App binary, and enforce it to use system Qt library and plugins path by export to environment variables.
bash script (/home/YourAppName.sh):
#!/bin/bash export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH export QT_PLUGIN_PATH=/lib/x86_64-linux-gnu/qt5/plugins /home/YourAppName
make it executable:
chmod +x /home/YourAppName.sh
Create a YourAppName.desktop file linked to the bash script for launch our app:
[Desktop Entry] Exec=/home/YourAppName.sh Icon= Name=YourAppName description Path=/home Terminal=false Type=Application
- Set persistent path globally. This will make Qt Creator unable to launch due to Qt Creator's startup script to enforce use of Qt build library!
edit '/etc/environment', and export path virables:
LD_LIBRARY_PATH=/lib/x86_64-linux-gnu QT_PLUGIN_PATH=/lib/x86_64-linux-gnu/qt5/plugins
Logout (or better restart) system, and your Qt app will now use Native QFileDialog.
The above solutions are based on Debian KDE, Qt5, please adjust the settings according to your system and Qt version.