[Qt-interest] Accessibility for Menus and List Views
Murielle Descerisiers
murielle.descerisiers at gmail.com
Sat Jul 25 01:57:11 CEST 2009
Hello,
I am creating a dictionary program, and though it's aimed at the
general public, I would like the interface to be available to screen
readers (synthetic speech), for people with visual disability. In
particular, I am testing with the NVDA reader
(http://www.nvda-project.org). Now, the QWidget class offers
setAccessibleName() and setAccessibleDescription() functions, which
work perfectly. But I am puzzled what to do with menus and list views,
because their individual items are not QWidget. Outside of that class,
only QStandardItem offers an accessibility function, and unfortunately
I'm required to use a different list model. Anyhow, what I ended up
doing is catching the hovered(), entered() and similar signals from
every menu, action and list view, and calling setAccessibleName() on
the active container or view port. Here's how it looks (sorry for the
French names) :
QList<QMenu *> listeMenus = findChildren<QMenu *>();
foreach(QMenu *menu, listeMenus)
connect(menu, SIGNAL(aboutToShow()), this, SLOT(EvenementAccessibiliteMenu()));
QList<QListView *> listeBoites = findChildren<QListView *>();
foreach(QListView *boite, listeBoites) {
boite->setMouseTracking(true);
connect(boite, SIGNAL(entered(QModelIndex)), this,
SLOT(EvenementAccessibiliteBoite(QModelIndex)));
}
QList<QAction *> listeActions = findChildren<QAction *>();
foreach(QAction *action, listeActions)
if(action->isSeparator() == false)
connect(action, SIGNAL(hovered()), this,
SLOT(EvenementAccessibiliteAction()));
void classePrincipale::EvenementAccessibiliteAction()
{
QWidget *controle(QApplication::activePopupWidget ());
if(controle) {
QAction *action(qobject_cast<QAction *>(sender()));
controle->setAccessibleName(action->iconText());
}
}
void classePrincipale::EvenementAccessibiliteMenu()
{
if(sender()->parent() == menuBarre) {
QMenu *menu(qobject_cast<QMenu *>(sender()));
menuBarre->setAccessibleName(menu->title().replace("&", ""));
}
else {
QWidget *controle(QApplication::activePopupWidget ());
if(controle) {
QMenu *menu(qobject_cast<QMenu *>(sender()));
controle->setAccessibleName(menu->title().replace("&", ""));
}
}
}
void classePrincipale::EvenementAccessibiliteBoite(const QModelIndex &index)
{
QListView *boite(qobject_cast<QListView *>(sender()));
boite->viewport()->setAccessibleName(ExtraireLemme(index.data().toString()));
}
Now, my question : Is this the right approach ? It works more or less,
but it's very inelegant, and whenever an item is activated (not
hovered but activated), NVDA says "unknown object".
Of course, I saw the QAccessible and QAccessibleInterface classes, but
they seem without practical use, though I would like very much to be
wrong and to learn how they relate to menus and list views.
Thank you in advance for any information,
Murielle
More information about the Qt-interest-old
mailing list