In a Qt GUI application, QApplication::style()->objectName()
will return the current style, for example "windowsvista".
How/where does it choose this default style, and what information does it use to decide?
In a Qt GUI application, QApplication::style()->objectName()
will return the current style, for example "windowsvista".
How/where does it choose this default style, and what information does it use to decide?
Qt comes with builtin styles, these are (on my 5.9.2):
each one having its own class, derived from QStyle
.
To see which ones are available (it depends on Qt build configuration):
const auto & styles = QStyleFactory::keys();
for(const auto & s : styles)
{
qDebug() << s;
}
Custom plugins (i.e. libraries in the QTDIR/plugins/styles directory) would be shown as well, if present.
How the default style is chosen?
Default style is searched in QApplication
method style()
, in qapplication.cpp file, in this order:
QT_STYLE_OVERRIDE
(this is set in QApplicationPrivate::process_cmdline()
);QApplicationPrivate::desktopStyleKey()
(this method loads a list of styles from the current platform theme and select the first name from this list that is present in the QStyleFactory::keys()
list);QStyleFactory::keys()
list.If a style could not be determined, the function will assert
Q_ASSERT(!"No styles available!");
In the documentation:
Qt contains a set of QStyle subclasses that emulate the styles of the different platforms supported by Qt (QWindowsStyle, QMacStyle etc.).
You can set the style by using a key: windowsvista
for example, fusion
, macintosh
, etc. When using any key, the style returned will be a subclass of QStyle. Depending on the platform you're using, you will have access to a certain number of keys.
How/where does it choose this default style
It is done in the QStyleFactory source file. You can also take a look a the QStyle source file to get a hang of what's going on.
what information does it use to decide
The default style is platform dependent, and then you can choose any style among the keys at your disposition on this platform.
© 2022 - 2024 — McMap. All rights reserved.