Linux - Support system's theme change
-
The problem is, that your app runs on gnome and this is gtk and not Qt. If you use KDE, your app will use the system theme!
-
I've used kubuntu 10.10 in the past and there it's ok. But that's kde.
Are you sure about that Scylla?
It seems strange to me.A workaround could be to get the system style in code and set it like you did.
-
Here it works as expected (Kubuntu 1010). If you don't use a hard coded style, it should work on KDE.
-
You need to have a GTK style engine in Qt, so that Qt will use GTK styling by default. http://code.google.com/p/qgtkstyle/
EDIT: Okay, that link is outdated. But anyway, that piece of code allows to use GTK styles in Qt, I don’t know where is instructions to use it.
-
For what it is worth, I quickly installed Kubuntu 11.04, and ran my application on it, and its look didn't match that of the KDE theme. Then again, I built my application on Ubuntu 11.04 and copied it over to my Kubuntu system, so it might explain...? (Note: I don't use any hard-coded style and, in fact, don't want to have to do that at all, since my application may end up being use on different flavours of Linux.)
Eddy: what do you mean by "get the system style in code"?
Smar: I have seen that Qt has QGtkStyle class, but on my Ubuntu box, QT_NO_STYLE_GTK is defined and therefore QGtkStyle is not available. Then again, as I mentioned before, I don't want to have to use styles. I would just hope that things would somehow work... :)
-
Hi Alan,
There is an example called stylesheet that uses the solution I talked about.
@QString defaultStyle = QApplication::style()->metaObject()->className();@
have a look in the StyleSheetEditor constructor.
About Ubuntu 11.04 : I read that they are leaving gtk. Maybe this has something to do with it? Since prior versions of ubuntu didn't have this problem.
-
Thanks Eddy. I just had a quick look and for my application under Ubuntu 11.04, the following code:
@QRegExp regExp(".(.*)\+?Style");
QString defaultStyle = QApplication::style()->metaObject()->className();qDebug() << "BEFORE:" << defaultStyle;
if (regExp.exactMatch(defaultStyle))
defaultStyle = regExp.cap(1);qDebug() << "AFTER:" << defaultStyle;@
returns:
bq. BEFORE: "QCleanlooksStyle"
AFTER: "Cleanlooks"This is already the style that my application uses, so I am not sure it helps...?
-
Did you try to set it in code using that string eventually? I suppose you did.
The reason why I ask is that you told us before that setting it using code went well.
If it's not, there must be a problem with the them I suppose on your system. -
Well, I did try indeed (using app->setStyle(new QCleanlookStyle), even though app->style() would return QCleanLookStyle before I set the 'new' style.
Otherwise, I did say that hard setting the style worked in the sense that the style gets applied, but I also said that if I change the theme, then my application doesn't respond to the change.
As I also said, the Qt examples behave the same as my application (i.e. don't respond to a change in the theme) while Qt Creator works as expected (i.e. responds to a change in the theme).
-
Sorry it couldn't help you out. It was worth trying I guess.
-
No worries, and yes always worth trying. I guess that if I was to study Qt Creator's source code carefully, then I would find out how they do it...
-
Sounds like a good idea. And you could learn other usefull things.
Keep us posted.
-
Oh, I already have from Qt Creator's source code. :) It's just that I am still struggling about the overall structure of the source code, so I tend to use it as a last resource.