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 !

    https://bugreports.qt.io/browse/QTBUG-86105


  • Lifetime Qt Champion

    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#getOpenFileNames

    On 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 set QFileDialog::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 :

    eeea7823-5f12-44b6-ba49-9e535cbdc844-image.png

    when true :
    12241095-0a32-4f06-a7ed-54738f4e603e-image.png



  • @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" with nullptr where pointers are concerned, and the new args 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.


Log in to reply