简体   繁体   English

在Pure Qt应用程序中使用KDE系统主题

[英]Using KDE System Theme in Pure Qt Application

I'm developing a Qt4 app and running it under gnome, but I would really like it to use a KDE system theme (Oxygen) and color scheme (Obsidian Coast). 我正在开发Qt4应用程序并在gnome下运行它,但我真的希望它使用KDE系统主题(氧气)和配色方案(黑曜石海岸)。 Unfortunately, the application doesn't seem to respond to changes in systemsettings . 不幸的是,该应用程序似乎未响应systemsettings更改。

I am at least able to get the app to use the theme I want programmatically by setting the QStyle: 我至少可以通过设置QStyle来使应用程序以编程方式使用我想要的主题:

QApplication app( argc, argv );
app.setStyle(QStyleFactory::create("oxygen"));

but I don't know of any similar approach for setting the color scheme, and this is kind of ugly anyway. 但我不知道采用任何类似的方法来设置配色方案,无论如何这都是丑陋的。

Interestingly, I've already developed some PyQt4 apps on this same machine and they pick up changes in systemsettings just fine. 有趣的是,我已经在同一台机器上开发了一些PyQt4应用程序,它们很好地接受了systemsettings更改。 I'm not really sure why a C++ Qt4 app would behave differently. 我不太确定为什么C ++ Qt4应用程序的行为会有所不同。

One more note: I've noticed that changing the window appearance via the gnome dialog will affect my C++ qt window's appearance - so perhaps Gnome is overriding my KDE configuration somehow? 另一个注意事项:我注意到通过gnome对话框更改窗口外观会影响C ++ qt窗口的外观-那么Gnome可能以某种方式覆盖了我的KDE配置?

The only solution I've found is to let the environment do the work for you, as noted here: https://forum.kde.org/viewtopic.php?f=17&t=90720 我发现的唯一解决方案是让环境为您完成工作,如此处所述: https : //forum.kde.org/viewtopic.php?f=17&t=90720

A snip from the posts: 帖子摘录:

So you wish to start Amarok with a different colour scheme to the rest of KDE? 因此,您希望使用与KDE其余部分不同的配色方案来启动Amarok吗? You can do this by having a different set of settings for it. 您可以通过为其设置不同的设置来完成此操作。

Open Konsole, and enter "export KDEHOME=$HOME/.kde4-amarok/" Then run "systemsettings" and configure how you would like Amarok to appear ( colour scheme, etc. ) Finally, run "amarok" to start Amarok itself. 打开Konsole,输入“ export KDEHOME = $ HOME / .kde4-amarok /”,然后运行“ systemsettings”并配置您希望Amarok出现的方式(配色方案等)。最后,运行“ amarok”以启动Amarok本身。

This will work for QT applications as well, but you can't set the style from within the application like you're trying ( app.setStyle(QStyleFactory::create("oxygen"); ) You'll have to use a slightly messier method: 这同样适用于QT应用程序,但是您不能像尝试那样从应用程序内部设置样式( app.setStyle(QStyleFactory::create("oxygen"); )您必须使用一些信使方法:

sys.argv.append("--style=Oxygen")

This will read the argument from the environment, and won't make a whole new Oxygen theme instance, (assuming you've set the KDEHOME environment to somewhere in your project, and you've already customized that) and will then use that KDEHOME to read the colors from and use the Oxygen theme. 这将从环境中读取参数,并且不会创建一个全新的Oxygen主题实例,(假设您已将KDEHOME环境设置为项目中的某个位置,并且您已经自定义了该环境),然后将使用该KDEHOME读取颜色并使用“ Oxygen主题。

Maybe they'll change this for QT5... (The ability to set a style programmatically) 也许他们会为QT5更改此设置(以编程方式设置样式的功能)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM