Add constant property QStyleHints::accessibility
This property bundles together accessibility settings that can be used by styles to change how they draw different widgets and/or controls. The only property that it contains currently is contrastPreference. This property can be used to determine if the user has enabled a high contrast setting on the platform that the Qt application is running on. We might add more *accessibility* settings, like color blind hints, to QAccessibilityHints in the future. [ChangeLog][Gui][QStyleHints] Added class QAccessibilityHints, which can be accessed from QStyleHints. This singleton contains a single property contrastPreference which can be used to determine if the platform has enabled a high contrast setting or not. More accessibility settings might be added to QAccessibilityHints in the future. Task-number: QTBUG-133595 Change-Id: I93c6be81d29f65058eeda00328f4d9e966921de6 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
e808b38d4b
commit
d8ac4cd869
@ -90,6 +90,7 @@ qt_internal_add_module(Gui
|
|||||||
image/qppmhandler.cpp image/qppmhandler_p.h
|
image/qppmhandler.cpp image/qppmhandler_p.h
|
||||||
image/qxbmhandler.cpp image/qxbmhandler_p.h
|
image/qxbmhandler.cpp image/qxbmhandler_p.h
|
||||||
image/qxpmhandler.cpp image/qxpmhandler_p.h
|
image/qxpmhandler.cpp image/qxpmhandler_p.h
|
||||||
|
kernel/qaccessibilityhints.cpp kernel/qaccessibilityhints.h kernel/qaccessibilityhints_p.h
|
||||||
kernel/qclipboard.cpp kernel/qclipboard.h
|
kernel/qclipboard.cpp kernel/qclipboard.h
|
||||||
kernel/qcursor.cpp kernel/qcursor.h kernel/qcursor_p.h
|
kernel/qcursor.cpp kernel/qcursor.h kernel/qcursor_p.h
|
||||||
kernel/qeventpoint.cpp kernel/qeventpoint.h kernel/qeventpoint_p.h
|
kernel/qeventpoint.cpp kernel/qeventpoint.h kernel/qeventpoint_p.h
|
||||||
|
61
src/gui/kernel/qaccessibilityhints.cpp
Normal file
61
src/gui/kernel/qaccessibilityhints.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (C) 2025 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#include "qaccessibilityhints.h"
|
||||||
|
#include "qaccessibilityhints_p.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
void QAccessibilityHintsPrivate::updateContrastPreference(Qt::ContrastPreference contrastPreference)
|
||||||
|
{
|
||||||
|
if (m_contrastPreference == contrastPreference)
|
||||||
|
return;
|
||||||
|
m_contrastPreference = contrastPreference;
|
||||||
|
|
||||||
|
Q_Q(QAccessibilityHints);
|
||||||
|
emit q->contrastPreferenceChanged(contrastPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
QAccessibilityHintsPrivate *QAccessibilityHintsPrivate::get(QAccessibilityHints *q)
|
||||||
|
{
|
||||||
|
Q_ASSERT(q);
|
||||||
|
return q->d_func();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\class QAccessibilityHints
|
||||||
|
\since 6.10
|
||||||
|
\brief The QAccessibilityHints class contains platform specific accessibility hints and settings.
|
||||||
|
\inmodule QtGui
|
||||||
|
|
||||||
|
This class bundles together platform specific accessibility settings, and can be accessed from
|
||||||
|
\l QStyleHints::accessibility.
|
||||||
|
|
||||||
|
\sa QStyleHints
|
||||||
|
*/
|
||||||
|
|
||||||
|
QAccessibilityHints::QAccessibilityHints(QObject *parent)
|
||||||
|
: QObject(*(new QAccessibilityHintsPrivate), parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\property QAccessibilityHints::contrastPreference
|
||||||
|
\brief The contrast mode set by the system.
|
||||||
|
|
||||||
|
This property can be used by the application to determine what contrast settings the system
|
||||||
|
is currently using.
|
||||||
|
|
||||||
|
Qt styles use this property in order to adjust palette colors and outlines.
|
||||||
|
|
||||||
|
\sa Qt::ColorScheme, QGuiApplication::palette(), QEvent::PaletteChange
|
||||||
|
\since 6.10
|
||||||
|
*/
|
||||||
|
Qt::ContrastPreference QAccessibilityHints::contrastPreference() const
|
||||||
|
{
|
||||||
|
Q_D(const QAccessibilityHints);
|
||||||
|
return d->m_contrastPreference;
|
||||||
|
}
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#include "moc_qaccessibilityhints.cpp"
|
30
src/gui/kernel/qaccessibilityhints.h
Normal file
30
src/gui/kernel/qaccessibilityhints.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2025 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#ifndef QACCESSIBILITYHINTS_H
|
||||||
|
#define QACCESSIBILITYHINTS_H
|
||||||
|
|
||||||
|
#include <QtGui/qtguiglobal.h>
|
||||||
|
#include <QtCore/qobject.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QAccessibilityHintsPrivate;
|
||||||
|
|
||||||
|
class Q_GUI_EXPORT QAccessibilityHints : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_DECLARE_PRIVATE(QAccessibilityHints)
|
||||||
|
Q_PROPERTY(Qt::ContrastPreference contrastPreference READ contrastPreference NOTIFY contrastPreferenceChanged FINAL REVISION(6, 10))
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QAccessibilityHints(QObject *parent = nullptr);
|
||||||
|
Qt::ContrastPreference contrastPreference() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void contrastPreferenceChanged(Qt::ContrastPreference contrastPreference);
|
||||||
|
};
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // QACCESSIBILITYHINTS_H
|
37
src/gui/kernel/qaccessibilityhints_p.h
Normal file
37
src/gui/kernel/qaccessibilityhints_p.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2025 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#ifndef QACCESSIBILITYHINTS_P_H
|
||||||
|
#define QACCESSIBILITYHINTS_P_H
|
||||||
|
|
||||||
|
//
|
||||||
|
// W A R N I N G
|
||||||
|
// -------------
|
||||||
|
//
|
||||||
|
// This file is not part of the Qt API. It exists purely as an
|
||||||
|
// implementation detail. This header file may change from version to
|
||||||
|
// version without notice, or even be removed.
|
||||||
|
//
|
||||||
|
// We mean it.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "qaccessibilityhints.h"
|
||||||
|
|
||||||
|
#include <QtCore/private/qobject_p.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QAccessibilityHintsPrivate : public QObjectPrivate
|
||||||
|
{
|
||||||
|
Q_DECLARE_PUBLIC(QAccessibilityHints)
|
||||||
|
public:
|
||||||
|
void updateContrastPreference(Qt::ContrastPreference contrastPreference);
|
||||||
|
|
||||||
|
static QAccessibilityHintsPrivate *get(QAccessibilityHints *q);
|
||||||
|
private:
|
||||||
|
Qt::ContrastPreference m_contrastPreference = Qt::ContrastPreference::NoPreference;
|
||||||
|
};
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // QACCESSIBILITYHINTS_P_H
|
@ -1589,8 +1589,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
|
|||||||
Q_UNUSED(platformExplicitlySelected);
|
Q_UNUSED(platformExplicitlySelected);
|
||||||
|
|
||||||
init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
|
init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
|
||||||
if (const QPlatformTheme *theme = platformTheme())
|
QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
|
||||||
QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(theme->colorScheme());
|
|
||||||
|
|
||||||
if (!icon.isEmpty())
|
if (!icon.isEmpty())
|
||||||
forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
|
forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
|
||||||
@ -2820,10 +2819,7 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::
|
|||||||
|
|
||||||
void QGuiApplicationPrivate::handleThemeChanged()
|
void QGuiApplicationPrivate::handleThemeChanged()
|
||||||
{
|
{
|
||||||
const auto newColorScheme = platformTheme() ? platformTheme()->colorScheme()
|
QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
|
||||||
: Qt::ColorScheme::Unknown;
|
|
||||||
QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(newColorScheme);
|
|
||||||
|
|
||||||
updatePalette();
|
updatePalette();
|
||||||
|
|
||||||
QIconLoader::instance()->updateSystemTheme();
|
QIconLoader::instance()->updateSystemTheme();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#include "qaccessibilityhints_p.h"
|
||||||
#include <qstylehints.h>
|
#include <qstylehints.h>
|
||||||
#include "qstylehints_p.h"
|
#include "qstylehints_p.h"
|
||||||
#include <qpa/qplatformintegration.h>
|
#include <qpa/qplatformintegration.h>
|
||||||
@ -178,6 +179,22 @@ void QStyleHints::setColorScheme(Qt::ColorScheme scheme)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\property QStyleHints::accessibility
|
||||||
|
\brief The application's accessibility hints.
|
||||||
|
|
||||||
|
The accessibility hints encapsulates platform dependent accessibility settings
|
||||||
|
such as whether the user wishes the application to be in high contrast or not.
|
||||||
|
|
||||||
|
\sa QAccessibilityHints
|
||||||
|
\since 6.10
|
||||||
|
*/
|
||||||
|
const QAccessibilityHints *QStyleHints::accessibility() const
|
||||||
|
{
|
||||||
|
Q_D(const QStyleHints);
|
||||||
|
return d->accessibilityHints();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets the \a mousePressAndHoldInterval.
|
Sets the \a mousePressAndHoldInterval.
|
||||||
\internal
|
\internal
|
||||||
@ -705,6 +722,26 @@ void QStyleHintsPrivate::updateColorScheme(Qt::ColorScheme colorScheme)
|
|||||||
emit q->colorSchemeChanged(colorScheme);
|
emit q->colorSchemeChanged(colorScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
|
||||||
|
Helper function that updates the style hints when the theme changes
|
||||||
|
*/
|
||||||
|
void QStyleHintsPrivate::update(const QPlatformTheme *theme)
|
||||||
|
{
|
||||||
|
Q_ASSERT(theme);
|
||||||
|
updateColorScheme(theme->colorScheme());
|
||||||
|
QAccessibilityHintsPrivate::get(accessibilityHints())->updateContrastPreference(theme->contrastPreference());
|
||||||
|
}
|
||||||
|
|
||||||
|
QAccessibilityHints *QStyleHintsPrivate::accessibilityHints() const
|
||||||
|
{
|
||||||
|
Q_Q(const QStyleHints);
|
||||||
|
if (!m_accessibilityHints)
|
||||||
|
const_cast<QStyleHintsPrivate *>(this)->m_accessibilityHints = new QAccessibilityHints(const_cast<QStyleHints*>(q));
|
||||||
|
return m_accessibilityHints;
|
||||||
|
}
|
||||||
|
|
||||||
QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q)
|
QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q)
|
||||||
{
|
{
|
||||||
Q_ASSERT(q);
|
Q_ASSERT(q);
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
class QPlatformIntegration;
|
class QPlatformIntegration;
|
||||||
class QStyleHintsPrivate;
|
class QStyleHintsPrivate;
|
||||||
|
class QAccessibilityHints;
|
||||||
|
|
||||||
class Q_GUI_EXPORT QStyleHints : public QObject
|
class Q_GUI_EXPORT QStyleHints : public QObject
|
||||||
{
|
{
|
||||||
@ -57,6 +57,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject
|
|||||||
Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme WRITE setColorScheme
|
Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme WRITE setColorScheme
|
||||||
RESET unsetColorScheme NOTIFY colorSchemeChanged FINAL)
|
RESET unsetColorScheme NOTIFY colorSchemeChanged FINAL)
|
||||||
Q_PROPERTY(bool menuSelectionWraps READ menuSelectionWraps STORED false CONSTANT FINAL REVISION(6, 10))
|
Q_PROPERTY(bool menuSelectionWraps READ menuSelectionWraps STORED false CONSTANT FINAL REVISION(6, 10))
|
||||||
|
Q_PROPERTY(const QAccessibilityHints* accessibility READ accessibility CONSTANT FINAL REVISION(6, 10))
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
|
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
|
||||||
@ -103,6 +104,7 @@ public:
|
|||||||
Qt::ColorScheme colorScheme() const;
|
Qt::ColorScheme colorScheme() const;
|
||||||
void setColorScheme(Qt::ColorScheme scheme);
|
void setColorScheme(Qt::ColorScheme scheme);
|
||||||
void unsetColorScheme() { setColorScheme(Qt::ColorScheme::Unknown); }
|
void unsetColorScheme() { setColorScheme(Qt::ColorScheme::Unknown); }
|
||||||
|
const QAccessibilityHints* accessibility() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void cursorFlashTimeChanged(int cursorFlashTime);
|
void cursorFlashTimeChanged(int cursorFlashTime);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <private/qguiapplication_p.h>
|
#include <private/qguiapplication_p.h>
|
||||||
#include "qstylehints.h"
|
#include "qstylehints.h"
|
||||||
|
#include "qaccessibilityhints.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -43,11 +44,15 @@ public:
|
|||||||
|
|
||||||
Qt::ColorScheme colorScheme() const { return m_colorScheme; }
|
Qt::ColorScheme colorScheme() const { return m_colorScheme; }
|
||||||
void updateColorScheme(Qt::ColorScheme colorScheme);
|
void updateColorScheme(Qt::ColorScheme colorScheme);
|
||||||
|
void update(const QPlatformTheme *theme);
|
||||||
|
|
||||||
|
QAccessibilityHints *accessibilityHints() const;
|
||||||
|
|
||||||
static QStyleHintsPrivate *get(QStyleHints *q);
|
static QStyleHintsPrivate *get(QStyleHints *q);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
|
Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
|
||||||
|
QAccessibilityHints* m_accessibilityHints = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user