Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QfileDialog not using native dialogs on KDE Plasma 5.18
Forum Updated to NodeBB v4.3 + New Features

QfileDialog not using native dialogs on KDE Plasma 5.18

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 2.3k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kamui
    wrote on last edited by kamui
    #1

    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

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamui
        wrote on last edited by
        #3

        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();
        }
        
        JonBJ 1 Reply Last reply
        0
        • K kamui

          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();
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamui
            wrote on last edited by kamui
            #5

            @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

            JonBJ 1 Reply Last reply
            2
            • K kamui

              @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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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.

              R 1 Reply Last reply
              1
              • R Offline
                R Offline
                Robert Hairgrove
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • JonBJ JonB

                  @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.

                  R Offline
                  R Offline
                  Robert Hairgrove
                  wrote on last edited by
                  #8

                  @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).

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Robert Hairgrove
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      j4m3s
                      wrote on last edited by
                      #10

                      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):
                      Screenshot_20240905_011438.png

                      Pic #2:
                      Screenshot_20240905_011638.png

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        j4m3s
                        wrote on last edited by
                        #11

                        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?

                        Screenshot_20240905_194429.png

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          j4m3s
                          wrote on last edited by j4m3s
                          #12

                          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.

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved