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!");