Qt Widgets accessibility
In the kit: .github/skills/desktop-a11y-specialist/references/qt-accessibility.md.
-
This file as plain text, at
https://letitglow.app/ahg/kit/raw/.github/skills/desktop-a11y-specialist/references/qt-accessibility.md - Everything in the kit
Copy it into ChatGPT or another assistant
Read the plain text first
Qt Widgets accessibility
Read this when the scope holds Qt Widgets code: .ui files from Qt Designer, or C++ or Python (PyQt, PySide) that builds QWidget subclasses. Qt Quick and QML are out of scope here.
Where a widget's accessible name comes from
Qt's accessibility layer computes the name from the first of these that is set. The order is the same in Qt 5.15 and Qt 6 (QAccessibleWidget::text and the per-widget overrides in qtbase/src/widgets/accessible/).
For buttons, check boxes and radio buttons (QAbstractButton):
accessibleName.- The button's own
text, with the&mnemonic stripped. - Then the same fallbacks as any other widget, below.
For any other widget, including line edits, combo boxes and spin boxes:
accessibleName.- A window's title, for top-level windows.
- A buddy label: the text of a
QLabelwhosebuddyis this widget and that has the same parent widget, with the&mnemonic stripped. - If no such label exists and the parent is a
QGroupBox, the group box's title.
A QGroupBox itself is named last by its own title, after accessibleName and the fallbacks above.
Two properties never become the name:
toolTipbecomes the accessible Description, whenaccessibleDescriptionis not set.- A
QLineEdit'splaceholderTextalso becomes the Description, and only when there is no other description.
NVDA reads the Description, so an icon-only button that has only a tooltip, or a line edit that has only a placeholder, can sound named in an NVDA spot check. Its Name is still empty, and anything that relies on the Name, such as Accessibility Insights checks and speech input commands, has nothing to use. Do not treat an NVDA pass as proof that a widget has a name.
What to check
- Every interactive widget has a name from one of the sources above. Report a widget with none as WCAG 4.1.2 Name, Role, Value.
- Icon-only
QPushButtonandQToolButtonfail most often. AtoolTipis good to have, but the fix isaccessibleName(or visible text). Severity is serious: the control cannot be identified. - Line edits named only by a placeholder need a buddy label or an
accessibleName. The placeholder disappears when the user types. This matches the web rule that a placeholder is not a label. - Buddy labels name the field only when the label and the field share a parent widget. A label in a different container leaves the field unnamed; set
accessibleNameor move the label. A buddy also gives the field its keyboard mnemonic, so check the label text has an&for one. - Names set in code (
setAccessibleName(...)in the dialog's source rather than in the.uifile) count for the widget they are called on. Match the call to the widget'sobjectNamein the same dialog's.uifile before you clear a finding; the sameobjectNamein another dialog is a different widget. focusPolicyset toQt::NoFocuson an interactive widget is a WCAG 2.1.1 Keyboard finding only when its function cannot be reached from the keyboard another way. A read-only display, or a toolbar button that repeats a menu item or has a keyboard shortcut, passes. Record the exceptions you accept so a re-audit does not raise them again.- Tab order: every
<tabstop>in a.uifile names a widget that exists in that file, and the order follows the visual layout (WCAG 2.4.3 Focus Order).
Examples
A .ui fragment where each widget gets its name from a source Qt uses:
<widget class="QLabel" name="searchLabel">
<property name="text"><string>&Search:</string></property>
<property name="buddy"><cstring>searchField</cstring></property>
</widget>
<widget class="QLineEdit" name="searchField">
<property name="placeholderText"><string>Title or user name</string></property>
</widget>
<widget class="QToolButton" name="copyButton">
<property name="accessibleName"><string>Copy password</string></property>
<property name="toolTip"><string>Copy password</string></property>
</widget>The same in C++:
searchLabel->setBuddy(searchField); // names searchField; Alt+S on Windows and Linux
copyButton->setAccessibleName(tr("Copy password"));
copyButton->setToolTip(tr("Copy password")); // description, for sighted users tooSources
- Qt accessibility overview
qaccessiblewidget.cpp, Name and Descriptionsimplewidgets.cpp, buttons and line edits
Based on a contribution by @chrisnestrud (#218), checked against the qtbase source.