diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2022-02-17 18:46:30 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2022-02-24 12:16:41 +0100 |
commit | ee143fe27dfe2824dae5d8cbc1d1b799506e0f69 (patch) | |
tree | 7b9901c40c74ea4cd5199b47d490f7e0f4549289 | |
parent | 282c4eaf9327470f05e0f2822eac8fa86f2be994 (diff) |
qquickapplication: Add styleHints property
Implements a styleHints property to QQuickApplication for accessing QStyleHints
so it can be utilized in a way that's compatible with tooling and compilers.
[ChangeLog][QtQuick][New Feature] Qt.styleHints should now be accessed as
a property of QQuickApplication via Application.styleHints
Fixes: QTBUG-100993
Change-Id: I377c59072678a67d20f519cb5d329863111f295b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/qml/qml/qqmlbuiltinfunctions.cpp | 24 | ||||
-rw-r--r-- | src/quick/util/qquickapplication.cpp | 31 | ||||
-rw-r--r-- | src/quick/util/qquickapplication_p.h | 3 | ||||
-rw-r--r-- | src/quick/util/qquickforeignutils_p.h | 8 |
4 files changed, 46 insertions, 20 deletions
diff --git a/src/qml/qml/qqmlbuiltinfunctions.cpp b/src/qml/qml/qqmlbuiltinfunctions.cpp index 9213bd7c2d..565e0a085d 100644 --- a/src/qml/qml/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/qqmlbuiltinfunctions.cpp @@ -262,28 +262,12 @@ The following functions are also on the Qt object. \since 5.5 The \c styleHints object provides platform-specific style hints and settings. - See the QStyleHints documentation for further details. + See the \l QStyleHints documentation for further details. - \note The \c styleHints object is only available when using the Qt Quick module. - - The following example uses the \c styleHints object to determine whether an - item should gain focus on mouse press or touch release: - \code - import QtQuick 2.4 + You should access StyleHints via \l Application::styleHints instead. + See \l StyleHints for more details. - MouseArea { - id: button - - onPressed: { - if (!Qt.styleHints.setFocusOnTouchRelease) - button.forceActiveFocus() - } - onReleased: { - if (Qt.styleHints.setFocusOnTouchRelease) - button.forceActiveFocus() - } - } - \endcode + \note The \c styleHints object is only available when using the Qt Quick module. */ /*! diff --git a/src/quick/util/qquickapplication.cpp b/src/quick/util/qquickapplication.cpp index 0ed3990738..e850249b65 100644 --- a/src/quick/util/qquickapplication.cpp +++ b/src/quick/util/qquickapplication.cpp @@ -210,6 +210,32 @@ QT_BEGIN_NAMESPACE */ /*! + \qmlproperty StyleHints Application::styleHints + + The \c styleHints property provides platform-specific style hints and settings. + See the \l QStyleHints documentation for further details. + + The following example uses \c styleHints to determine whether an + item should gain focus on mouse press or touch release: + \code + import QtQuick + + MouseArea { + id: button + + onPressed: { + if (!Application.styleHints.setFocusOnTouchRelease) + button.forceActiveFocus() + } + onReleased: { + if (Application.styleHints.setFocusOnTouchRelease) + button.forceActiveFocus() + } + } + \endcode + */ + +/*! \qmlsignal Application::aboutToQuit() This signal is emitted when the application is about to quit the main @@ -273,6 +299,11 @@ QString QQuickApplication::displayName() const return QGuiApplication::applicationDisplayName(); } +QStyleHints *QQuickApplication::styleHints() +{ + return QGuiApplication::styleHints(); +} + void QQuickApplication::setDisplayName(const QString &displayName) { return QGuiApplication::setApplicationDisplayName(displayName); diff --git a/src/quick/util/qquickapplication_p.h b/src/quick/util/qquickapplication_p.h index dd67b4b11d..d8f4b3a6ee 100644 --- a/src/quick/util/qquickapplication_p.h +++ b/src/quick/util/qquickapplication_p.h @@ -58,6 +58,7 @@ #include <QtQml/private/qqmlglobal_p.h> #include <QtGui/qfont.h> +#include <QtGui/qstylehints.h> #include <QtCore/qobject.h> @@ -73,6 +74,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickApplication : public QQmlApplication Q_PROPERTY(QFont font READ font CONSTANT) Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) Q_PROPERTY(QQmlListProperty<QQuickScreenInfo> screens READ screens NOTIFY screensChanged) + Q_PROPERTY(QStyleHints *styleHints READ styleHints CONSTANT) QML_NAMED_ELEMENT(Application) QML_SINGLETON @@ -89,6 +91,7 @@ public: QQmlListProperty<QQuickScreenInfo> screens(); QString displayName() const; void setDisplayName(const QString &displayName); + QStyleHints *styleHints(); Q_SIGNALS: void activeChanged(); diff --git a/src/quick/util/qquickforeignutils_p.h b/src/quick/util/qquickforeignutils_p.h index 038d5fd30e..0f7869531f 100644 --- a/src/quick/util/qquickforeignutils_p.h +++ b/src/quick/util/qquickforeignutils_p.h @@ -67,6 +67,14 @@ QT_BEGIN_NAMESPACE +struct QStyleHintsForeign +{ + Q_GADGET + QML_FOREIGN(QStyleHints) + QML_ANONYMOUS + QML_ADDED_IN_VERSION(6, 4) +}; + #if QT_CONFIG(validator) struct QValidatorForeign { |