How to get QFileDialog system in Qt5?

I created file dialogs for selecting files in a Qt application. When switching to Qt5, I encounter regression, the dialogue with the file is much worse when linking to Qt5, not Qt4:

Qt4

Qt4 File Dialog

Qt5

Qt5 File Dialog

For example, it is very difficult for a user to navigate to network shared directories.

The code is as simple as this one:

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 as 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 screenshot of the Qt4 file dialog box.

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


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

enter image description here

+5
source share
1 answer

The following steps for me on Ubuntu 16.04 are more a workaround than a real solution:

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

Then, assuming that you want to start the my_app application from the terminal, launch it as follows (we mean the space after = ):

 $ QT_QPA_PLATFORMTHEME= my_app 

This is due to the fact that according to the error report on the launchpad , the problem is with the Ubuntu appmenu-qt5 package: the package causes the 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 Disabling the platform theme via QT_QPA_PLATFORMTHEME= before starting the application changes this behavior locally.

Edit: Using the described approach, the global menu may not work in my_app .

+4
source

Source: https://habr.com/ru/post/1260510/


All Articles