21

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.

Community
  • 1
  • 1
NIA
  • 2,523
  • 22
  • 32

4 Answers4

15

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.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
  • 1
    So there is absolutely no way to extract Oxygen as theme from KDE code, yes? I hoped I could play with it and make it build with Qt5... – NIA Feb 17 '13 at 15:06
  • @NIA Since Oxygen depends on KDE and KDE can only use Qt4, you can't make Oxygen use Qt5 since loading Qt5 and Qt4 at the same time is not possible. – Nikos C. Feb 17 '13 at 15:12
  • Ah, got it. Will not use Qt5 in KDE until KDE 5, OK. – NIA Feb 17 '13 at 15:50
  • 1
    I thought years back, since it was required for the GTK version, Oxygen removed the dependency on kdelibs? – Jonathan Baldwin Aug 19 '13 at 02:02
  • @JonathanBaldwin oxygen-gtk is a completely independent project form oxygen-qt, it just reimplemented all routines to access kde settings and to process kde palette etc. to be free from kdelibs dependency (and useful in e.g. XFCE without additional dependencies even on Qt). Even with Qt5 oxygen is still dependent on KDE frameworks. – Ruslan Jan 24 '16 at 18:00
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.

peppe
  • 21,934
  • 4
  • 55
  • 70
4

try

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

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

kwirz
  • 76
  • 2
  • Thanks for the idea, I haven't thought about it. I've updated my question with a few lines about it. – NIA Apr 13 '13 at 07:38
1

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!

DirkMausF
  • 715
  • 5
  • 14