I installed Qt5 along with Qt4 on my Kubuntu 12.10 linux machine and noticed the following:
我在Kubuntu 12.10 linux上安装了Qt5和Qt4,并注意到以下内容:
- Program compiled with Qt4 has native KDE look and feel. I use default KDE's Oxygen theme and so does my program (note smooth gradient with title and blue selection of focused widget);
- 用Qt4编译的程序具有本机KDE外观。我使用默认KDE的氧主题,我的程序也一样(注意平滑渐变和标题和蓝色选择的焦点小部件);
- But when recompiled with Qt5 without any changes to code, it uses different style (seems like it is called Fusion) and it looks awkward and out-of-place (see right pic)
- 但是当使用Qt5重新编译时,不需要对代码进行任何修改,它使用了不同的样式(似乎它被称为Fusion),并且看起来很笨拙而且不合适(参见右图)
What I want is pretty straitforward: I want my app to fit surrounding system, i.e. look native always. When using Qt4, I'm used to having this by default. Qt5 also seemed to have normal native look in Windows. But what do I have to do to have the same in Kubuntu as well? And, ideally, everywhere? I mean, I do not want to force linux build of my app to strictly use Oxygen. I want it to use the theme that is currently set in KDE: just like it was in good old Qt4.
我想要的是非常直截了当的:我想让我的应用适合周围的系统,也就是说,看起来总是土里土气的。在使用Qt4时,我习惯默认使用Qt4。Qt5在Windows中似乎也具有正常的本机外观。但是在Kubuntu中,我要做什么才能做到同样的事情呢?理想情况下,无处不在?我的意思是,我不想强迫linux构建我的应用程序严格使用Oxygen。我希望它使用当前在KDE中设置的主题:就像它在旧的Qt4中一样。
It seems like app code is not relevant to this issue: I didn't play with any QStyle's in it, it's pretty much typical Qt's hello-world. But just in case it's on GitHub.
似乎应用程序代码与这个问题无关:我没有使用任何QStyle,它几乎是典型的Qt的hello-world。但万一在GitHub上。
UPD: @peppe has given pretty sufficient answer on why this problem happens (Oxygen theme in KDE is compiled against Qt4 and not usable by Qt5). But I'm still looking for the answer on how to fix this? I tried to find Oxygen theme source to play around with, but didn't find anything except Firefox theme.
UPD: @peppe给出了关于这个问题发生的充分答案(KDE中的Oxygen主题是根据Qt4编译的,Qt5不能使用)。但我还在寻找如何解决这个问题的答案?我试图找到Oxygen主题源来玩,但是除了Firefox主题外什么也没找到。
UPD2: @kwirz suggested an interesting idea: force the app to use GTK+ theme, and enable oxygen-gtk in KDE settings that makes GTK windows look similar to Oxygen. On the one hand, it indeed looks closer to Oxygen:
UPD2: @kwirz提出了一个有趣的想法:强制应用使用GTK+主题,并在KDE设置中启用氧- GTK,使GTK窗口看起来与氧相似。一方面,它看起来确实更接近氧气:
But on the other hand, we already see the little differences: readonly line edit turns gray, focused button is still not hightlighted, etc. Unfortunately, when trying to apply this technique to more complex widgets, even more artifacts appear (especially on combo box and spinner):
但是,另一方面,我们已经看到了一些细微的差别:readonly行编辑变成灰色,聚焦按钮仍然没有被高亮显示,等等。不幸的是,当试图将这种技术应用到更复杂的小部件时,甚至出现了更多的工件(尤其是组合框和spinner):
So it seems like this techique cannot be a complete solution, but still very useful is simple cases.
看起来这个技巧并不是一个完整的解决方案,但仍然非常有用的是简单的例子。
4 个解决方案
#1
14
Oxygen is part of KDE, so that's where you find it. It's not a stand-alone theme. You cannot build KDE against Qt 5, it's not supported. The next major version of KDE (KDE 5) will be using Qt 5.
氧是KDE的一部分,这就是你找到它的地方。这不是一个独立的主题。您不能根据qt5构建KDE,它不受支持。KDE的下一个主要版本(KDE 5)将使用Qt 5。
So right now, there's absolutely nothing you can do. If you want your application to look and behave nice in KDE 4, use Qt 4.
所以现在,你什么都做不了。如果希望应用程序在KDE 4中表现良好,请使用qt4。
#2
9
It's not your app -- it's just that Oxygen is compiled against Qt 4 and not Qt 5, so Qt 5 can't use it and falls back to the default style ("fusion"). Remember that styles are actually plugins -- i.e. code, subject to API/ABI requirements in order to be loaded and used. You need an Oxygen style compiled against Qt 5.
它不是你的应用程序——它只是氧是根据qt4而不是qt5编译的,所以qt5不能使用它并退回到默认样式(“fusion”)。请记住,样式实际上是插件——即代码,根据API/ABI需求来加载和使用。您需要一个基于qt5编译的Oxygen样式。
#3
4
try
试一试
QApplication::setStyle(QStyleFactory::create("GTK+"));
as workaround, it looks native, if oxygen-gtk is installed.
作为解决方案,如果安装了氧-gtk,它看起来是本地的。
#4
0
Start your Qt5 application with parameter:
使用参数启动Qt5应用程序:
-style=gtk
There is no global setting that i know of, that makes this for all QT5 apps.
我所知道的没有全局设置,这使得QT5应用程序都可以使用。
Good luck!
好运!
#1
14
Oxygen is part of KDE, so that's where you find it. It's not a stand-alone theme. You cannot build KDE against Qt 5, it's not supported. The next major version of KDE (KDE 5) will be using Qt 5.
氧是KDE的一部分,这就是你找到它的地方。这不是一个独立的主题。您不能根据qt5构建KDE,它不受支持。KDE的下一个主要版本(KDE 5)将使用Qt 5。
So right now, there's absolutely nothing you can do. If you want your application to look and behave nice in KDE 4, use Qt 4.
所以现在,你什么都做不了。如果希望应用程序在KDE 4中表现良好,请使用qt4。
#2
9
It's not your app -- it's just that Oxygen is compiled against Qt 4 and not Qt 5, so Qt 5 can't use it and falls back to the default style ("fusion"). Remember that styles are actually plugins -- i.e. code, subject to API/ABI requirements in order to be loaded and used. You need an Oxygen style compiled against Qt 5.
它不是你的应用程序——它只是氧是根据qt4而不是qt5编译的,所以qt5不能使用它并退回到默认样式(“fusion”)。请记住,样式实际上是插件——即代码,根据API/ABI需求来加载和使用。您需要一个基于qt5编译的Oxygen样式。
#3
4
try
试一试
QApplication::setStyle(QStyleFactory::create("GTK+"));
as workaround, it looks native, if oxygen-gtk is installed.
作为解决方案,如果安装了氧-gtk,它看起来是本地的。
#4
0
Start your Qt5 application with parameter:
使用参数启动Qt5应用程序:
-style=gtk
There is no global setting that i know of, that makes this for all QT5 apps.
我所知道的没有全局设置,这使得QT5应用程序都可以使用。
Good luck!
好运!