Reputation: 13025
I'm writing a GUI application using Qt 4.7 on Windows 7 Ultimate 32 bit. I'd like to let users change the GUI style from main menu. Several QStyles (QCDEStyle, QWindowsStyle, QCleanlooksStyle etc) can be selected from the menu and I'm using QApplication::setStyle()
to set the new style.
I'd like to have an option to return back to the default style for Windows 7. By default style, what I mean is to use the style returned by QApplication::style()
before any style is set explicitly using QApplication::setStyle()
. Following is the attempt that will not work:
QStyle *default_style;
// During initialization of QMainWindow
default_style = QApplication::style();
// When default style is chosen from main menu
QApplication::setStyle(default_style);
The above will not work because QApplication::setStyle()
takes ownership of the object and deletes previous QStyle*
.
How can I change QApplication
style to the default one? Thanks.
Upvotes: 1
Views: 879
Reputation: 8277
After a bit of sourcediving, it turns out styles have their object names set to the style name, so you can say:
QString defaultStyle = this->style()->objectName();
and later
qApp->setStyle(defaultStyle);
Upvotes: 5