From 4c4ac0d976bc5daa89d6f845fa1a28479b00847f Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Thu, 19 Oct 2017 17:03:11 +0200 Subject: [PATCH] Fix accessibility info for tri-state checkboxes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The state information provided by QAccessibleInterface::state() was not correctly reflecting the state of tri-state checkboxes: checkStateMixed was never set. This change fixes this issue and also adds accessibility update notifications for changes in checkStateMixed, which were missing. Change-Id: Ia4a114559d5a957ca85bf2f169a6cece2c98d077 Reviewed-by: Jan Arve Sæther --- src/widgets/accessible/simplewidgets.cpp | 2 +- src/widgets/widgets/qcheckbox.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index 73de51ff45..2fd664e13a 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -170,7 +170,7 @@ QAccessible::State QAccessibleButton::state() const if (b->isChecked()) state.checked = true; #if QT_CONFIG(checkbox) - else if (cb && cb->checkState() == Qt::PartiallyChecked) + if (cb && cb->checkState() == Qt::PartiallyChecked) state.checkStateMixed = true; #endif if (b->isDown()) diff --git a/src/widgets/widgets/qcheckbox.cpp b/src/widgets/widgets/qcheckbox.cpp index 9b49916774..235508535d 100644 --- a/src/widgets/widgets/qcheckbox.cpp +++ b/src/widgets/widgets/qcheckbox.cpp @@ -45,6 +45,9 @@ #include "qstyle.h" #include "qstyleoption.h" #include "qevent.h" +#ifndef QT_NO_ACCESSIBILITY +#include "qaccessible.h" +#endif #include "private/qabstractbutton_p.h" @@ -243,6 +246,9 @@ Qt::CheckState QCheckBox::checkState() const void QCheckBox::setCheckState(Qt::CheckState state) { Q_D(QCheckBox); +#ifndef QT_NO_ACCESSIBILITY + bool noChange = d->noChange; +#endif if (state == Qt::PartiallyChecked) { d->tristate = true; d->noChange = true; @@ -257,6 +263,15 @@ void QCheckBox::setCheckState(Qt::CheckState state) d->publishedState = state; emit stateChanged(state); } + +#ifndef QT_NO_ACCESSIBILITY + if (noChange != d->noChange) { + QAccessible::State s; + s.checkStateMixed = true; + QAccessibleStateChangeEvent event(this, s); + QAccessible::updateAccessibility(&event); + } +#endif }