Question

I installed Qt5 along with Qt4 on my Kubuntu 12.10 linux machine and noticed the following:

  • 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);
  • 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)

Native look of Qt4 appNOT native look of Qt5 app

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.

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.

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.

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:

Semi-native look of Qt5 app using oxygen-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):

Artifacts on QComboBox and QTimeEdit using oxygen-gtk

So it seems like this techique cannot be a complete solution, but still very useful is simple cases.

Was it helpful?

Solution

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.

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.

OTHER TIPS

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.

try

QApplication::setStyle(QStyleFactory::create("GTK+"));

as workaround, it looks native, if oxygen-gtk is installed.

Start your Qt5 application with parameter:

-style=gtk

There is no global setting that i know of, that makes this for all QT5 apps.

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top