Linux - Support system's theme change
-
Hi,
I have just noticed that though my application works as I would expect on Linux (Ubuntu 11.04), if I change my system's theme, then my application doesn't fully handle the change. The window border decoration will respect the theme, but the menus, dialog buttons, etc. won't.
I have just checked with the Qt (4.7.3) demos (which I manually built on my Ubuntu 11.04 box) and it's the same. They, in fact, use the same (default?) theme as my application. However, everything works as I would expect using Qt Creator 2.2.1.
So, what is the difference between my application / the Qt demos and Qt Creator? How do I go about ensuring that my application respects the system's theme?
Cheers, Alan.
P.S.: I have just checked on Windows and Mac OS X, and as far as I can tell everything works as expected, i.e. my application handles changes in the system's theme without any problem.
-
If I programmatically set a style, e.g.
@app->setStyle(new QPlastiqueStyle);@
then the style is properly set, but it obviously doesn't respond to any change to the system's theme, and is therefore not what I want.In fact, I don't use and don't want to use any particular style. I just want my application to use the 'default' system style and respond to any change to it. Nothing more nothing less.
-
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...?
-
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).