yan bellavance
yan bellavance

Reputation: 4840

Can I run a Qt application with a specific theme?

Can I run a Qt application with a specific theme? I would like the application to use an OS theme that is different than the current OS theme.

Upvotes: 14

Views: 20192

Answers (2)

Thomas Vincent
Thomas Vincent

Reputation: 2224

QT doc says :

void QApplication::setDesktopSettingsAware ( bool on ) [static]

Sets whether Qt should use the system's standard colors, fonts, etc., to on. By default, this is true.This function must be called before creating the QApplication object, like this:

int main(int argc, char *argv[])
{
    QApplication::setDesktopSettingsAware(false);
    QApplication app(argc, argv);
    ...
    return app.exec();
}

So it should work out of the box. But I noticed that when I run my application in QtSDK the system color scheme is 'not found', I mean my QApplications seems not settings aware. I deployed some of them on a nice ubuntu installation and I get the rigth theme. I don't know what's under the hood though but certainly something about $QTDIR content ...

Upvotes: 4

Arnold Spence
Arnold Spence

Reputation: 22282

Yes. In main() before you create your instance of QApplication, you can call QApplication::setStyle("plastique") for example. Some of the other style strings would be: "windows", "motif", "cde", "plastique" and "cleanlooks" and depending on the platform, "windowsxp", "windowsvista" and "macintosh".

Calling the other overloaded version of this function would work too such as QApplication::setStyle(new QWindowsXPStyle).

It could also be specified on the command line when launching the application using the -style switch:

./myapplication -style motif

Upvotes: 21

Related Questions