From 958a4c9087e03502d0173735df4611a7f96a0463 Mon Sep 17 00:00:00 2001 From: Christoph Schleifenbaum Date: Thu, 14 Nov 2013 13:56:19 +0100 Subject: QApp: Method to check for native style usage. Adds QApplicationPrivate::usesNativeStyle to check whether the QApplication is using the native platform style. This can be needed internally to decided whether to let the platform plugins do stuff or do it interally, style dependent. E.g. letting the platform plugin popup a QMenu vs. letting the style draw one. Change-Id: Ibb5e11a4d9d1d2824685ff146786a9354ceef43c Reviewed-by: BogDan Vatra --- src/widgets/kernel/qapplication.cpp | 21 +++++++++++++++++++++ src/widgets/kernel/qapplication_p.h | 7 +++++++ 2 files changed, 28 insertions(+) (limited to 'src') diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index b4c4ffe7c7..0b983e7a9d 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -146,6 +146,20 @@ static void clearSystemPalette() QApplicationPrivate::sys_pal = 0; } +static QByteArray get_style_class_name() +{ + QScopedPointer s(QStyleFactory::create(QApplicationPrivate::desktopStyleKey())); + if (!s.isNull()) + return s->metaObject()->className(); + return QByteArray(); +} + +static QByteArray nativeStyleClassName() +{ + static QByteArray name = get_style_class_name(); + return name; +} + #ifdef Q_OS_WINCE int QApplicationPrivate::autoMaximizeThreshold = -1; bool QApplicationPrivate::autoSipEnabled = false; @@ -372,6 +386,8 @@ void qt_init_tooltip_palette(); void qt_cleanup(); QStyle *QApplicationPrivate::app_style = 0; // default application style +bool QApplicationPrivate::overrides_native_style = false; // whether native QApplication style is + // overridden, i.e. not native QString QApplicationPrivate::styleOverride; // style override #ifndef QT_NO_STYLE_STYLESHEET @@ -997,6 +1013,8 @@ QStyle *QApplication::style() Q_ASSERT(!"No styles available!"); return 0; } + QApplicationPrivate::overrides_native_style = + app_style->objectName() != QApplicationPrivate::desktopStyleKey(); } // take ownership of the style QApplicationPrivate::app_style->setParent(qApp); @@ -1061,6 +1079,9 @@ void QApplication::setStyle(QStyle *style) QStyle *old = QApplicationPrivate::app_style; // save + QApplicationPrivate::overrides_native_style = + nativeStyleClassName() == QByteArray(style->metaObject()->className()); + #ifndef QT_NO_STYLE_STYLESHEET if (!QApplicationPrivate::styleSheet.isEmpty() && !qobject_cast(style)) { // we have a stylesheet already and a new style is being set diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 0284a613d4..d5efb62dda 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -150,6 +150,12 @@ public: bool canQuit(); #endif + //style + static bool usesNativeStyle() + { + return !overrides_native_style; + } + bool notify_helper(QObject *receiver, QEvent * e); void construct( @@ -184,6 +190,7 @@ public: static QSize app_strut; static QWidgetList *popupWidgets; static QStyle *app_style; + static bool overrides_native_style; static int app_cspec; static QPalette *sys_pal; static QPalette *set_pal; -- cgit v1.2.3