5

I created file dialogs to select files within a Qt application. When migrating to Qt5 I encounter a regression, the file dialog is much poorer when linking against Qt5 rather than Qt4:

Qt4

Qt4 file dialog

Qt5

Qt5 file dialog

For example it is very hard for an user to navigate to the network mounted share directories.

The code is as simple as this:

QString path;
path = QFileDialog::getExistingDirectory(this, tr("Pick a file"));

QFileDialog::DontUseNativeDialog does not change anything.

My OS is Ubuntu 16.04, I have both nautilus (3.14.3) and nemo (2.8.7) installed. nemo is configured to be the default file manager:

xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search

Every other application seems to use the same dialog as the Qt4 file dialog screenshot.

How do I get the "old" file dialog in Qt5?


If I try with QT_QPA_PLATFORMTHEME= ./my_app then I get this:

enter image description here

Victor Lamoine
  • 389
  • 1
  • 2
  • 21
  • Somehow, the platform integration doesn't work in Qt 5. The `DontUseNativeDialog` option is incorrect: Qt 4 did use the native dialog, it seems. Perhaps Qt 5 wasn't built with the correct platform integration plugin, or such integration plugin doesn't exist yet. – Kuba hasn't forgotten Monica Nov 29 '16 at 14:22
  • Or, t looks like you're using a Qt version w/o the support for the Gnome (GTK?) file dialog... – peppe Nov 30 '16 at 21:35
  • I am using Qt5 binaries from the Ubuntu repositories – Victor Lamoine Dec 01 '16 at 09:47

1 Answers1

4

The following works for me on Ubuntu 16.04 – it is more of a workaround than an actual solution, though:

Edit: First make sure that the package libqt5libqgtk2 is installed. It brings the GTK2 bindings for Qt5. If the package is not installed, the file choosers will look like the last screenshot shown in the question above.

Then, assuming you want to launch your application my_app from a terminal, launch it as follows (mind the space after =):

$ QT_QPA_PLATFORMTHEME= my_app

This is because, according to a bug report on launchpad, there seems to be a problem with the Ubuntu package appmenu-qt5: the package forces Qt5 dialogs to become non-native as a side effect of explicitly setting QT_QPA_PLATFORMTHEME=appmenu-qt5 via /etc/profile.d/appmenu-qt5.sh. Unsetting the platform theme via QT_QPA_PLATFORMTHEME= before launching your application changes this behavior locally.

Edit: When using the described approach, however, the global menu might not work in my_app.

simon
  • 1,503
  • 8
  • 16
  • This does not provide a solution (looks worse for me) but describes the problem more precisely! – Victor Lamoine Jan 10 '17 at 15:42
  • @VictorLamoine Agreed that my suggestion is not an actual solution. I guess this could only be provided by fixing package `appmenu-qt5`. I hope it was of some help to you anyway. What do you mean by "looks worse for me"? Did you try? – simon Jan 10 '17 at 15:50
  • Oh, I see. What I forgot to mention: Do you have the Qt5 GTK2 platform theme installed already? It is the package `libqt5libqgtk2`. The combination of both did it for me. If it also works for you, I will update my answer respectively. – simon Jan 11 '17 at 08:35
  • Now, that is a solution! Thanks a lot. The global menu works for me – Victor Lamoine Jan 11 '17 at 08:50
  • Great! Glad I could help. – simon Jan 11 '17 at 09:01
  • As a final comment, you can even enforce this behavior directly in the code, by setting (or unsetting) the environment variable `QT_QPA_PLATFORMTHEME` from there. In Python, using PyQt5, this would look as follows: `os.environ["QT_QPA_PLATFORMTHEME"] = ""; app = QApplication([]); ...`. Don't know if that is a good idea though. – simon Jan 11 '17 at 10:04