Make an application follow the platform theme (Linux)
-
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_PLATFORMTHEMEvariable. 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 ? -
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
-
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
@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-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 ?
@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? -
@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 ?
@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_PLATFORMTHEMEenvironment variable tells Qt itself (theQGuiApplicationconstructor, 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 theqt6ctQPA Theme plugin, which itself is configured to load theKvantumstyle 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=1environment 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.
-
@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_PLATFORMTHEMEenvironment variable tells Qt itself (theQGuiApplicationconstructor, 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 theqt6ctQPA Theme plugin, which itself is configured to load theKvantumstyle 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=1environment 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.
@IgKh Thank you I get it now ! I'll try to build from another tool than QtCreator and see if the theme matches
-
@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?@Axel-Spoerl I am using only a window manager at the moment, though I will test my application on several desktop environments
-
@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_PLATFORMTHEMEenvironment variable tells Qt itself (theQGuiApplicationconstructor, 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 theqt6ctQPA Theme plugin, which itself is configured to load theKvantumstyle 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=1environment 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.
@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 oflddon 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 ?
-
@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 oflddon 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 ?
@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.