QAccessible Class

The QAccessible class provides enums and static functions related to accessibility. More...

Header: #include <QAccessible>
qmake: QT += gui

Public Types

struct State
enum Event { AcceleratorChanged, ActionChanged, ActiveDescendantChanged, Alert, AttributeChanged, …, VisibleDataChanged }
typedef Id
typedef InterfaceFactory
enum InterfaceType { TextInterface, ValueInterface, ActionInterface, TableInterface, TableCellInterface }
flags Relation
enum RelationFlag { Label, Labelled, Controller, Controlled, AllRelations }
enum Role { AlertMessage, Animation, Application, Assistant, Border, …, Window }
enum Text { Name, Description, Value, Help, Accelerator, UserText }
enum TextBoundaryType { CharBoundary, WordBoundary, SentenceBoundary, ParagraphBoundary, LineBoundary, NoBoundary }

Static Public Members

QAccessibleInterface *accessibleInterface(QAccessible::Id id)
void deleteAccessibleInterface(QAccessible::Id id)
void installFactory(QAccessible::InterfaceFactory factory)
bool isActive()
QAccessibleInterface *queryAccessibleInterface(QObject *object)
QAccessible::Id registerAccessibleInterface(QAccessibleInterface *iface)
void removeFactory(QAccessible::InterfaceFactory factory)
void setRootObject(QObject *object)
QAccessible::Id uniqueId(QAccessibleInterface *iface)
void updateAccessibility(QAccessibleEvent *event)

Detailed Description

This class is part of Accessibility for QWidget Applications.

Accessible applications can be used by people who are not able to use applications by conventional means.

The functions in this class are used for communication between accessible applications (also called AT Servers) and accessibility tools (AT Clients), such as screen readers and braille displays. Clients and servers communicate in the following way:

  • AT Servers notify the clients about events through calls to the updateAccessibility() function.
  • AT Clients request information about the objects in the server. The QAccessibleInterface class is the core interface, and encapsulates this information in a pure virtual API. Implementations of the interface are provided by Qt through the queryAccessibleInterface() API.

The communication between servers and clients is initialized by the setRootObject() function. Function pointers can be installed to replace or extend the default behavior of the static functions in QAccessible.

Qt supports Microsoft Active Accessibility (MSAA), macOS Accessibility, and the Unix/X11 AT-SPI standard. Other backends can be supported using QAccessibleBridge.

In the Unix/X11 AT-SPI implementation, applications become accessible when two conditions are met:

  • org.a11y.Status.IsEnabled DBus property is true
  • org.a11y.Status.ScreenReaderEnabled DBus property is true

An alternative to setting the DBus AT-SPI properties is to set the QT_LINUX_ACCESSIBILITY_ALWAYS_ON environment variable.

In addition to QAccessible's static functions, Qt offers one generic interface, QAccessibleInterface, that can be used to wrap all widgets and objects (e.g., QPushButton). This single interface provides all the metadata necessary for the assistive technologies. Qt provides implementations of this interface for its built-in widgets as plugins.

When you develop custom widgets, you can create custom subclasses of QAccessibleInterface and distribute them as plugins (using QAccessiblePlugin) or compile them into the application. Likewise, Qt's predefined accessibility support can be built as plugin (the default) or directly into the Qt library. The main advantage of using plugins is that the accessibility classes are only loaded into memory if they are actually used; they don't slow down the common case where no assistive technology is being used.

Qt also includes two convenience classes, QAccessibleObject and QAccessibleWidget, that inherit from QAccessibleInterface and provide the lowest common denominator of metadata (e.g., widget geometry, window title, basic help text). You can use them as base classes when wrapping your custom QObject or QWidget subclasses.

See also QAccessibleInterface.

Member Type Documentation

enum QAccessible::Event

This enum type defines accessible event types.

ConstantValueDescription
QAccessible::AcceleratorChanged0x80C0The keyboard accelerator for an action has been changed.
QAccessible::ActionChanged0x0101An action has been changed.
QAccessible::ActiveDescendantChanged0x0102 
QAccessible::Alert0x0002A system alert (e.g., a message from a QMessageBox)
QAccessible::AttributeChanged0x0103 
QAccessible::ContextHelpEnd0x000DContext help (QWhatsThis) for an object is finished.
QAccessible::ContextHelpStart0x000CContext help (QWhatsThis) for an object is initiated.
QAccessible::DefaultActionChanged0x80B0The default QAccessible::Action for the accessible object has changed.
QAccessible::DescriptionChanged0x800DThe object's QAccessible::Description changed.
QAccessible::DialogEnd0x0011A dialog (QDialog) has been hidden
QAccessible::DialogStart0x0010A dialog (QDialog) has been set visible.
QAccessible::DocumentContentChanged0x0104The contents of a text document have changed.
QAccessible::DocumentLoadComplete0x0105A document has been loaded.
QAccessible::DocumentLoadStopped0x0106A document load has been stopped.
QAccessible::DocumentReload0x0107A document reload has been initiated.
QAccessible::DragDropEnd0x000FA drag and drop operation is about to finished.
QAccessible::DragDropStart0x000EA drag and drop operation is about to be initiated.
QAccessible::Focus0x8005An object has gained keyboard focus.
QAccessible::ForegroundChanged0x0003A window has been activated (i.e., a new window has gained focus on the desktop).
QAccessible::HelpChanged0x80A0The QAccessible::Help text property of an object has changed.
QAccessible::HyperlinkEndIndexChanged0x0108The end position of the display text for a hypertext link has changed.
QAccessible::HyperlinkNumberOfAnchorsChanged0x0109The number of anchors in a hypertext link has changed, perhaps because the display text has been split to provide more than one link.
QAccessible::HyperlinkSelectedLinkChanged0x010AThe link for the selected hypertext link has changed.
QAccessible::HyperlinkStartIndexChanged0x010DThe start position of the display text for a hypertext link has changed.
QAccessible::HypertextChanged0x010EThe display text for a hypertext link has changed.
QAccessible::HypertextLinkActivated0x010BA hypertext link has been activated, perhaps by being clicked or via a key press.
QAccessible::HypertextLinkSelected0x010CA hypertext link has been selected.
QAccessible::HypertextNLinksChanged0x010F 
QAccessible::LocationChanged0x800BAn object's location on the screen has changed.
QAccessible::MenuCommand0x0018A menu item is triggered.
QAccessible::MenuEnd0x0005A menu has been closed (Qt uses PopupMenuEnd for all menus).
QAccessible::MenuStart0x0004A menu has been opened on the menubar (Qt uses PopupMenuStart for all menus).
QAccessible::NameChanged0x800CThe QAccessible::Name property of an object has changed.
QAccessible::ObjectAttributeChanged0x0110 
QAccessible::ObjectCreated0x8000A new object is created.
QAccessible::ObjectDestroyed0x8001An object is deleted.
QAccessible::ObjectHide0x8003An object is hidden; for example, with QWidget::hide(). Any children the object that is hidden has do not send this event. It is not sent when an object is hidden as it is being obcured by others.
QAccessible::ObjectReorder0x8004A layout or item view has added, removed, or moved an object (Qt does not use this event).
QAccessible::ObjectShow0x8002An object is displayed; for example, with QWidget::show().
QAccessible::PageChanged0x0111 
QAccessible::ParentChanged0x800FAn object's parent object changed.
QAccessible::PopupMenuEnd0x0007A pop-up menu has closed.
QAccessible::PopupMenuStart0x0006A pop-up menu has opened.
QAccessible::ScrollingEnd0x0013A scrollbar scroll operation has ended (the mouse has released the slider handle).
QAccessible::ScrollingStart0x0012A scrollbar scroll operation is about to start; this may be caused by a mouse press on the slider handle, for example.
QAccessible::SectionChanged0x0112 
QAccessible::SelectionAdd0x8007An item has been added to the selection in an item view.
QAccessible::SelectionRemove0x8008An item has been removed from an item view selection.
QAccessible::Selection0x8006The selection has changed in a menu or item view.
QAccessible::SelectionWithin0x8009Several changes to a selection has occurred in an item view.
QAccessible::SoundPlayed0x0001A sound has been played by an object
QAccessible::TableCaptionChanged0x0113A table caption has been changed.
QAccessible::TableColumnDescriptionChanged0x0114The description of a table column, typically found in the column's header, has been changed.
QAccessible::TableColumnHeaderChanged0x0115A table column header has been changed.
QAccessible::TableRowDescriptionChanged0x0117The description of a table row, typically found in the row's header, has been changed.
QAccessible::TableRowHeaderChanged0x0118A table row header has been changed.
QAccessible::TableSummaryChanged0x0119The summary of a table has been changed.
QAccessible::TextColumnChanged0x011DA text column has been changed.
QAccessible::VisibleDataChanged0x0122 

The values for this enum are defined to be the same as those defined in the IAccessible2 and MSAA specifications.

typedef QAccessible::Id

Synonym for unsigned, used by the QAccessibleInterface cache.

typedef QAccessible::InterfaceFactory

This is a typedef for a pointer to a function with the following signature:

 typedef QAccessibleInterface* myFactoryFunction(const QString &key, QObject *);

The function receives a QString and a QObject pointer, where the QString is the key identifying the interface. The QObject is used to pass on to the QAccessibleInterface so that it can hold a reference to it.

If the key and the QObject does not have a corresponding QAccessibleInterface, nullptr will be returned.

Installed factories are called by queryAccessibilityInterface() until one provides an interface.

enum QAccessible::InterfaceType

QAccessibleInterface supports several sub interfaces. In order to provide more information about some objects, their accessible representation should implement one or more of these interfaces.

Note: When subclassing one of these interfaces, QAccessibleInterface::interface_cast() needs to be implemented.

ConstantValueDescription
QAccessible::TextInterface0For text that supports selections or is more than one line. Simple labels do not need to implement this interface.
QAccessible::ValueInterface2For objects that are used to manipulate a value, for example slider or scroll bar.
QAccessible::ActionInterface3For interactive objects that allow the user to trigger an action. Basically everything that allows for example mouse interaction.
QAccessible::TableInterface5For lists, tables and trees.
QAccessible::TableCellInterface6For cells in a TableInterface object.

See also QAccessibleInterface::interface_cast(), QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, QAccessibleTableInterface, and QAccessibleTableCellInterface.

enum QAccessible::RelationFlag
flags QAccessible::Relation

This enum type defines bit flags that can be combined to indicate the relationship between two accessible objects.

ConstantValueDescription
QAccessible::Label0x00000001The first object is the label of the second object.
QAccessible::Labelled0x00000002The first object is labelled by the second object.
QAccessible::Controller0x00000004The first object controls the second object.
QAccessible::Controlled0x00000008The first object is controlled by the second object.
QAccessible::AllRelations0xffffffffUsed as a mask to specify that we are interesting in information about all relations

Implementations of relations() return a combination of these flags. Some values are mutually exclusive.

The Relation type is a typedef for QFlags<RelationFlag>. It stores an OR combination of RelationFlag values.

enum QAccessible::Role

This enum defines the role of an accessible object. The roles are:

ConstantValueDescription
QAccessible::AlertMessage0x00000008An object that is used to alert the user.
QAccessible::Animation0x00000036An object that displays an animation.
QAccessible::Application0x0000000EThe application's main window.
QAccessible::Assistant0x00000020An object that provids interactive help.
QAccessible::Border0x00000013An object that represents a border.
QAccessible::ButtonDropDown0x00000038A button that drops down a list of items.
QAccessible::ButtonDropGrid0x0000003AA button that drops down a grid.
QAccessible::ButtonMenu0x00000039A button that drops down a menu.
QAccessible::Canvas0x00000035An object that displays graphics that the user can interact with.
QAccessible::Caret0x00000007An object that represents the system caret (text cursor).
QAccessible::Cell0x0000001DA cell in a table.
QAccessible::Chart0x00000011An object that displays a graphical representation of data.
QAccessible::CheckBox0x0000002CAn object that represents an option that can be checked or unchecked. Some options provide a "mixed" state, e.g. neither checked nor unchecked.
QAccessible::Client0x0000000AThe client area in a window.
QAccessible::Clock0x0000003DA clock displaying time.
QAccessible::ColorChooser0x404A dialog that lets the user choose a color.
QAccessible::Column0x0000001BA column of cells, usually within a table.
QAccessible::ColumnHeader0x00000019A header for a column of data.
QAccessible::ComboBox0x0000002EA list of choices that the user can select from.
QAccessible::ComplementaryContent0x42CA part of the document or web page that is complementary to the main content, usually a landmark (see WAI-ARIA).
QAccessible::Cursor0x00000006An object that represents the mouse cursor.
QAccessible::Desktop0x00000082The object represents the desktop or workspace.
QAccessible::Dial0x00000031An object that represents a dial or knob.
QAccessible::Dialog0x00000012A dialog box.
QAccessible::Document0x0000000FA document, for example in an office application.
QAccessible::EditableText0x0000002AEditable text such as a line or text edit.
QAccessible::Equation0x00000037An object that represents a mathematical equation.
QAccessible::Footer0x40EA footer in a page (usually in documents).
QAccessible::Form0x410A web form containing controls.
QAccessible::Graphic0x00000028A graphic or picture, e.g. an icon.
QAccessible::Grip0x00000004A grip that the user can drag to change the size of widgets.
QAccessible::Grouping0x00000014An object that represents a logical grouping of other objects.
QAccessible::Heading0x414A heading in a document.
QAccessible::HelpBalloon0x0000001FAn object that displays help in a separate, short lived window.
QAccessible::HotkeyField0x00000032A hotkey field that allows the user to enter a key sequence.
QAccessible::Indicator0x00000027An indicator that represents a current value or item.
QAccessible::LayeredPane0x00000080An object that can contain layered children, e.g. in a stack.
QAccessible::Link0x0000001EA link to something else.
QAccessible::List0x00000021A list of items, from which the user can select one or more items.
QAccessible::ListItem0x00000022An item in a list of items.
QAccessible::MenuBar0x00000002A menu bar from which menus are opened by the user.
QAccessible::MenuItem0x0000000CAn item in a menu or menu bar.
QAccessible::NoRole0x00000000The object has no role. This usually indicates an invalid object.
QAccessible::Note0x41BA section whose content is parenthetic or ancillary to the main content of the resource.
QAccessible::Notification0x00000086An object that represents a notification (e.g. in the system tray). This role only has an effect on Linux.
QAccessible::PageTab0x00000025A page tab that the user can select to switch to a different page in a dialog.
QAccessible::PageTabList0x0000003CA list of page tabs.
QAccessible::Paragraph0x00000083A paragraph of text (usually found in documents).
QAccessible::Pane0x00000010A generic container.
QAccessible::PopupMenu0x0000000BA menu which lists options that the user can select to perform an action.
QAccessible::ProgressBar0x00000030The object displays the progress of an operation in progress.
QAccessible::PropertyPage0x00000026A property page where the user can change options and settings.
QAccessible::Button0x0000002BA button.
QAccessible::RadioButton0x0000002DAn object that represents an option that is mutually exclusive with other options.
QAccessible::Row0x0000001CA row of cells, usually within a table.
QAccessible::RowHeader0x0000001AA header for a row of data.
QAccessible::ScrollBar0x00000003A scroll bar, which allows the user to scroll the visible area.
QAccessible::Section0x00000085A section (in a document).
QAccessible::Separator0x00000015A separator that divides space into logical areas.
QAccessible::Slider0x00000033A slider that allows the user to select a value within a given range.
QAccessible::Sound0x00000005An object that represents a sound.
QAccessible::SpinBox0x00000034A spin box widget that allows the user to enter a value within a given range.
QAccessible::Splitter0x0000003EA splitter distributing available space between its child widgets.
QAccessible::StaticText0x00000029Static text, such as labels for other widgets.
QAccessible::StatusBar0x00000017A status bar.
QAccessible::Table0x00000018A table representing data in a grid of rows and columns.
QAccessible::Terminal0x00000081A terminal or command line interface.
QAccessible::TitleBar0x00000001The title bar caption of a window.
QAccessible::ToolBar0x00000016A tool bar, which groups widgets that the user accesses frequently.
QAccessible::ToolTip0x0000000DA tool tip which provides information about other objects.
QAccessible::Tree0x00000023A list of items in a tree structure.
QAccessible::TreeItem0x00000024An item in a tree structure.
QAccessible::UserRole0x0000ffffThe first value to be used for user defined roles.
QAccessible::WebDocument0x00000084HTML document, usually in a browser.
QAccessible::Whitespace0x0000003BBlank space between other objects.
QAccessible::Window0x00000009A top level window.

enum QAccessible::Text

This enum specifies string information that an accessible object returns.

ConstantValueDescription
QAccessible::Name0The name of the object. This can be used both as an identifier or a short description by accessible clients.
QAccessible::Description1A short text describing the object.
QAccessible::Value2The value of the object.
QAccessible::Help3A longer text giving information about how to use the object.
QAccessible::Accelerator4The keyboard shortcut that executes the object's default action.
QAccessible::UserText0x0000ffffThe first value to be used for user defined text.

enum QAccessible::TextBoundaryType

This enum describes different types of text boundaries. It follows the IAccessible2 API and is used in the QAccessibleTextInterface.

ConstantValueDescription
QAccessible::CharBoundary0Use individual characters as boundary.
QAccessible::WordBoundary1Use words as boundaries.
QAccessible::SentenceBoundary2Use sentences as boundary.
QAccessible::ParagraphBoundary3Use paragraphs as boundary.
QAccessible::LineBoundary4Use newlines as boundary.
QAccessible::NoBoundary5No boundary (use the whole text).

See also QAccessibleTextInterface.

Member Function Documentation

[static] QAccessibleInterface *QAccessible::accessibleInterface(QAccessible::Id id)

Returns the QAccessibleInterface belonging to the id.

Returns nullptr if the id is invalid.

[static] void QAccessible::deleteAccessibleInterface(QAccessible::Id id)

Removes the interface belonging to this id from the cache and deletes it. The id becomes invalid an may be re-used by the cache.

[static] void QAccessible::installFactory(QAccessible::InterfaceFactory factory)

Installs the InterfaceFactory factory. The last factory added is the first one used by queryAccessibleInterface().

[static] bool QAccessible::isActive()

Returns true if the platform requested accessibility information.

This function will return false until a tool such as a screen reader accessed the accessibility framework. It is still possible to use QAccessible::queryAccessibleInterface() even if accessibility is not active. But there will be no notifications sent to the platform.

It is recommended to use this function to prevent expensive notifications via updateAccessibility() when they are not needed.

[static] QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)

If a QAccessibleInterface implementation exists for the given object, this function returns a pointer to the implementation; otherwise it returns nullptr.

The function calls all installed factory functions (from most recently installed to least recently installed) until one is found that provides an interface for the class of object. If no factory can provide an accessibility implementation for the class the function loads installed accessibility plugins, and tests if any of the plugins can provide the implementation.

If no implementation for the object's class is available, the function tries to find an implementation for the object's parent class, using the above strategy.

All interfaces are managed by an internal cache and should not be deleted.

[static] QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)

Call this function to ensure that manually created interfaces are properly memory managed.

Must only be called exactly once per interface iface. This is implicitly called when calling queryAccessibleInterface, calling this function is only required when QAccessibleInterfaces are instantiated with the "new" operator. This is not recommended, whenever possible use the default functions and let queryAccessibleInterface() take care of this.

When it is necessary to reimplement the QAccessibleInterface::child() function and returning the child after constructing it, this function needs to be called.

[static] void QAccessible::removeFactory(QAccessible::InterfaceFactory factory)

Removes factory from the list of installed InterfaceFactories.

[static] void QAccessible::setRootObject(QObject *object)

Sets the root object of the accessible objects of this application to object. All other accessible objects are reachable using object navigation from the root object.

Normally, it isn't necessary to call this function, because Qt sets the QApplication object as the root object immediately before the event loop is entered in QApplication::exec().

Use QAccessible::installRootObjectHandler() to redirect the function call to a customized handler function.

See also queryAccessibleInterface().

[static] QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)

Returns the unique ID for the QAccessibleInterface iface.

[static] void QAccessible::updateAccessibility(QAccessibleEvent *event)

Notifies about a change that might be relevant for accessibility clients.

event provides details about the change. These include the source of the change and the nature of the change. The event should contain enough information give meaningful notifications.

For example, the type ValueChange indicates that the position of a slider has been changed.

Call this function whenever the state of your accessible object or one of its sub-elements has been changed either programmatically (e.g. by calling QLabel::setText()) or by user interaction.

If there are no accessibility tools listening to this event, the performance penalty for calling this function is small, but if determining the parameters of the call is expensive you can test QAccessible::isActive() to avoid unnecessary computation.