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. Make an application follow the platform theme (Linux)

Make an application follow the platform theme (Linux)

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 496 Views 2 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.
  • B Offline
    B Offline
    BastienSante
    wrote last edited by
    #1

    Hello everyone !

    I'm having some trouble getting themes for my note editor right, and don't know if this issue belongs here. A lot of Qt and KDE applications are able to follow a common theme, by using the QT_QPA_PLATFORMTHEME variable. How could I make my program be "aware" of this variable and have it's theme set to the one used by a theme manager ?

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote last edited by
      #2

      Hi,
      as a general remark, you don't need the environment variable.
      The platform theme is detected automatically.
      Please write a bit more about your use case:

      • which distro / window manager is used
      • which Qt version
      • what exactly is the issue, i.e. what doesn't work

      Software Engineer
      The Qt Company, Oslo

      B 1 Reply Last reply
      1
      • Axel SpoerlA Axel Spoerl

        Hi,
        as a general remark, you don't need the environment variable.
        The platform theme is detected automatically.
        Please write a bit more about your use case:

        • which distro / window manager is used
        • which Qt version
        • what exactly is the issue, i.e. what doesn't work
        B Offline
        B Offline
        BastienSante
        wrote last edited by
        #3

        @Axel-Spoerl Thanks for your answer !

        I am currently running Debian without a desktop environment, using Qt 6.10.1.
        Most Qt applications that I use automatically follow the style defined by Kvantum (except Krita). However, when I test my application from Qt creator or launch it from the build folder, the application simply has the default Fusion style.

        Should my application look for an environment variable during the initialization ?

        Axel SpoerlA I 2 Replies Last reply
        0
        • B BastienSante

          @Axel-Spoerl Thanks for your answer !

          I am currently running Debian without a desktop environment, using Qt 6.10.1.
          Most Qt applications that I use automatically follow the style defined by Kvantum (except Krita). However, when I test my application from Qt creator or launch it from the build folder, the application simply has the default Fusion style.

          Should my application look for an environment variable during the initialization ?

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote last edited by
          #4

          @BastienSante said in Make an application follow the platform theme (Linux):

          I am currently running Debian without a desktop environment

          I don't understand what you mean here.
          Debian w/o desktop environment is command-line only.
          How do you launch Creator in the first place?

          Software Engineer
          The Qt Company, Oslo

          B 1 Reply Last reply
          0
          • B BastienSante

            @Axel-Spoerl Thanks for your answer !

            I am currently running Debian without a desktop environment, using Qt 6.10.1.
            Most Qt applications that I use automatically follow the style defined by Kvantum (except Krita). However, when I test my application from Qt creator or launch it from the build folder, the application simply has the default Fusion style.

            Should my application look for an environment variable during the initialization ?

            I Offline
            I Offline
            IgKh
            wrote last edited by
            #5

            @BastienSante said in Make an application follow the platform theme (Linux):

            Should my application look for an environment variable during the initialization ?

            Nope. The QT_QPA_PLATFORMTHEME environment variable tells Qt itself (the QGuiApplication constructor, specifically) to load a specific Platform Theme plugin. It in turn can tell Qt to load other plugins - based on what you mentioned I guess you want to use the qt6ct QPA Theme plugin, which itself is configured to load the Kvantum style plugin. So no, you don't need or want to do anything with those variables yourself.

            The reason that it seemingly has no effect on your program is that Qt plugins are loaded from the prefix of a specific Qt installation; for a program that is linked against a specific Qt installation, it MUST load the plugins from the same installation. What is likely happening in your case is that qt6ct and Kvantum are installed as Debian packages and are built against the Qt that is built by Debian itself; however Qt Creator (if you install it not through the distribution) has its' own Qt installation - which is what it links your application against when you build in Qt Creator. That separate installation does not have the plugins you are asking, so it doesn't matter that the environment variable is set - they won't be found. You can see that if you run your application with the QT_DEBUG_PLUGINS=1 environment variable set; it will tell you what it is looking for and where.

            If that is indeed the case, you'll need to build all the relevant Qt plugins against that Qt installation and copy them to its' plugin folder. Do not attempt to simply copy the plugin files from the system; the APIs that Qt gives to plugin authors are not binary stable (unlike the APIs exported for application authors) and a crash is the likely outcome.

            B 2 Replies Last reply
            4
            • I IgKh

              @BastienSante said in Make an application follow the platform theme (Linux):

              Should my application look for an environment variable during the initialization ?

              Nope. The QT_QPA_PLATFORMTHEME environment variable tells Qt itself (the QGuiApplication constructor, specifically) to load a specific Platform Theme plugin. It in turn can tell Qt to load other plugins - based on what you mentioned I guess you want to use the qt6ct QPA Theme plugin, which itself is configured to load the Kvantum style plugin. So no, you don't need or want to do anything with those variables yourself.

              The reason that it seemingly has no effect on your program is that Qt plugins are loaded from the prefix of a specific Qt installation; for a program that is linked against a specific Qt installation, it MUST load the plugins from the same installation. What is likely happening in your case is that qt6ct and Kvantum are installed as Debian packages and are built against the Qt that is built by Debian itself; however Qt Creator (if you install it not through the distribution) has its' own Qt installation - which is what it links your application against when you build in Qt Creator. That separate installation does not have the plugins you are asking, so it doesn't matter that the environment variable is set - they won't be found. You can see that if you run your application with the QT_DEBUG_PLUGINS=1 environment variable set; it will tell you what it is looking for and where.

              If that is indeed the case, you'll need to build all the relevant Qt plugins against that Qt installation and copy them to its' plugin folder. Do not attempt to simply copy the plugin files from the system; the APIs that Qt gives to plugin authors are not binary stable (unlike the APIs exported for application authors) and a crash is the likely outcome.

              B Offline
              B Offline
              BastienSante
              wrote last edited by
              #6

              @IgKh Thank you I get it now ! I'll try to build from another tool than QtCreator and see if the theme matches

              1 Reply Last reply
              0
              • Axel SpoerlA Axel Spoerl

                @BastienSante said in Make an application follow the platform theme (Linux):

                I am currently running Debian without a desktop environment

                I don't understand what you mean here.
                Debian w/o desktop environment is command-line only.
                How do you launch Creator in the first place?

                B Offline
                B Offline
                BastienSante
                wrote last edited by
                #7

                @Axel-Spoerl I am using only a window manager at the moment, though I will test my application on several desktop environments

                1 Reply Last reply
                0
                • I IgKh

                  @BastienSante said in Make an application follow the platform theme (Linux):

                  Should my application look for an environment variable during the initialization ?

                  Nope. The QT_QPA_PLATFORMTHEME environment variable tells Qt itself (the QGuiApplication constructor, specifically) to load a specific Platform Theme plugin. It in turn can tell Qt to load other plugins - based on what you mentioned I guess you want to use the qt6ct QPA Theme plugin, which itself is configured to load the Kvantum style plugin. So no, you don't need or want to do anything with those variables yourself.

                  The reason that it seemingly has no effect on your program is that Qt plugins are loaded from the prefix of a specific Qt installation; for a program that is linked against a specific Qt installation, it MUST load the plugins from the same installation. What is likely happening in your case is that qt6ct and Kvantum are installed as Debian packages and are built against the Qt that is built by Debian itself; however Qt Creator (if you install it not through the distribution) has its' own Qt installation - which is what it links your application against when you build in Qt Creator. That separate installation does not have the plugins you are asking, so it doesn't matter that the environment variable is set - they won't be found. You can see that if you run your application with the QT_DEBUG_PLUGINS=1 environment variable set; it will tell you what it is looking for and where.

                  If that is indeed the case, you'll need to build all the relevant Qt plugins against that Qt installation and copy them to its' plugin folder. Do not attempt to simply copy the plugin files from the system; the APIs that Qt gives to plugin authors are not binary stable (unlike the APIs exported for application authors) and a crash is the likely outcome.

                  B Offline
                  B Offline
                  BastienSante
                  wrote last edited by
                  #8

                  @IgKh
                  I have made another test, building inside a different directory, outside of Qt Creator. Still, the themes provided by Kvantum do not apply. I have compared the outputs of ldd on the binaries of a correctly themed app and mine, and both call libraries in my system Qt install, not the one from Qt Creator.

                  When setting QT_DEBUG_PLUGINS to 1 and launching the app from a terminal, the output shows the plugins are detected, however I don't see any one having to do with themes. Maybe this plugin does not work with Qt 6.10.1 ?

                  I 1 Reply Last reply
                  0
                  • B BastienSante

                    @IgKh
                    I have made another test, building inside a different directory, outside of Qt Creator. Still, the themes provided by Kvantum do not apply. I have compared the outputs of ldd on the binaries of a correctly themed app and mine, and both call libraries in my system Qt install, not the one from Qt Creator.

                    When setting QT_DEBUG_PLUGINS to 1 and launching the app from a terminal, the output shows the plugins are detected, however I don't see any one having to do with themes. Maybe this plugin does not work with Qt 6.10.1 ?

                    I Offline
                    I Offline
                    IgKh
                    wrote last edited by
                    #9

                    @BastienSante said in Make an application follow the platform theme (Linux):

                    When setting QT_DEBUG_PLUGINS to 1 and launching the app from a terminal, the output shows the plugins are detected, however I don't see any one having to do with themes. Maybe this plugin does not work with Qt 6.10.1 ?

                    Well that probably means that the plugins aren't there... post the output generated by it (ideally as a link to a pastebin or gist, the output is quite long usually) and I could tell you perhaps.

                    1 Reply Last reply
                    0

                    • Login

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