Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtquickcontrols2nativestyleplugin.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtQml/qqml.h>
5#include <QtQuickControls2/private/qquickstyleplugin_p.h>
6#include <QtGui/qguiapplication.h>
7#include <QtGui/qpa/qplatformintegration.h>
8#include <QtGui/private/qguiapplication_p.h>
9#include <QtGui/qstylehints.h>
10#include <QtQuickTemplates2/private/qquicktheme_p.h>
11
12#include "qquicknativestyle.h"
13#include "qquickcommonstyle.h"
14
15#if defined(Q_OS_MACOS)
17#include "qquickmacfocusframe.h"
18#elif defined(Q_OS_WINDOWS)
20#endif
21
23
26
27using namespace QQC2;
28
30{
33
34public:
37
38 void initializeEngine(QQmlEngine *engine, const char *uri) override;
39 void initializeTheme(QQuickTheme *theme) override;
40 QString name() const override;
41
42#if defined(Q_OS_MACOS)
44#endif
45};
46
47static void deleteQStyle()
48{
49 // When we delete QStyle, it will free up it's own internal resources. Especially
50 // on macOS, this means releasing a lot of NSViews and NSCells from the QMacStyle
51 // destructor. If we did this from ~QtQuickControls2NativeStylePlugin, it would
52 // happen when the plugin was unloaded from a Q_DESTRUCTOR_FUNCTION in QLibrary,
53 // which is very late in the tear-down process, and after qGuiApp has been set to
54 // nullptr, NSApplication has stopped running, and perhaps also other static platform
55 // variables (e.g in AppKit?) has been deleted. And to our best guess, this is also why
56 // we see a crash in AppKit from the destructor in QMacStyle. So for this reason, we
57 // delete QStyle from a post routine rather than from the destructor.
59}
60
63{
66}
67
69{
70 if (!qGuiApp)
71 return;
72
73 // QGuiApplication is still running, so we need to remove the post
74 // routine to not be called after we have been unloaded.
77}
78
80{
81 return QStringLiteral("NativeStyle");
82}
83
85{
87 Q_UNUSED(uri);
88 // Enable commonstyle as a reference style while
89 // the native styles are under development.
90 QStyle *style = nullptr;
91 if (qEnvironmentVariable("QQC2_COMMONSTYLE") == QStringLiteral("true")) {
92 style = new QCommonStyle;
93 } else {
94 const QString envStyle = qEnvironmentVariable("QQC2_STYLE");
95 if (!envStyle.isNull()) {
96 if (envStyle == QLatin1String("common"))
97 style = new QCommonStyle;
98#if defined(Q_OS_MACOS)
99 else if (envStyle == QLatin1String("mac"))
100 style = new QMacStyle;
101#endif
102#if defined(Q_OS_WINDOWS)
103 else if (envStyle == QLatin1String("windows"))
104 style = new QWindowsStyle;
105 else if (envStyle == QLatin1String("windowsxp"))
106 style = new QWindowsXPStyle;
107#endif
108 }
109 if (!style) {
110#if defined(Q_OS_MACOS)
111 style = new QMacStyle;
112#elif defined(Q_OS_WINDOWS)
113 style = new QWindowsXPStyle;
115 qobject_cast<QWindowsStyle *>(style)->refreshPalette();
116#else
117 style = new QCommonStyle;
118#endif
119 }
120 }
121
122#if defined(Q_OS_MACOS)
123 m_focusFrame.reset(new QQuickMacFocusFrame());
124#endif
125
128}
129
131{
132}
133
135
136#include "qtquickcontrols2nativestyleplugin.moc"
static QStyleHints * styleHints()
Returns the application's style hints.
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static void setStyle(QStyle *style)
The QWindowsStyle class provides a Microsoft Windows-like look and feel.
The QWindowsXPStyle class provides a Microsoft Windows XP-like look and feel.
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
void initializeEngine(QQmlEngine *engine, const char *uri) override
Initializes the extension from the uri using the engine.
Combined button and popup list for selecting options.
void qAddPostRoutine(QtCleanUpFunction p)
void qRemovePostRoutine(QtCleanUpFunction p)
#define qGuiApp
#define QQmlExtensionInterface_iid
#define Q_GHS_KEEP_REFERENCE(S)
static const QQmlModuleRegistration registration("QtQml", qml_register_types_QtQml)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
#define Q_OBJECT
#define Q_PLUGIN_METADATA(x)
#define Q_UNUSED(x)
QT_BEGIN_NAMESPACE void qml_register_types_QtQuick_NativeStyle()
static void deleteQStyle()
QJSEngine engine
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent