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 from the current OS theme.

+6
source share
2 answers

Yes. In main() , before creating an instance of QApplication, you can call QApplication::setStyle("plastique") , for example. Some of the other style lines will be: "windows", "motif", "cde", "plastique" and "cleanlook" and depending on the platform "windowsxp", "windowsvista" and "macintosh".

Calling another overloaded version of this function will work just like QApplication::setStyle(new QWindowsXPStyle) .

It can also be specified on the command line when starting the application using the key-style:

 ./myapplication -style motif 
+13
source

QT doc says:

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

Sets whether Qt should use standard system colors, fonts, etc. for inclusion. This is true by default. This function must be called before the QApplication object is created, for example:

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

Therefore, 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 that my QApplication seems not configured. I deployed some of them in a nice ubuntu installation, and I get a rigorous theme. I don't know what's under the hood, but of course, something about the contents of $QTDIR ...

+2
source

Source: https://habr.com/ru/post/893020/


All Articles