PDA

View Full Version : Accessibility for QAction contained in QMenu



AndreiTuicu
10th May 2014, 20:44
I'm having a problem. I can't seem to make the screen reader tell the shorcut keys along with the option's name for a QAction contained in a QMenu. For example instead of "Open...", I would like the screen reader to tell me "Open... Ctrl+O".

As I see it, the problem is that the screen reader only sees the QAction::text() property. So if I do something like this:


QMenuBar* menus = this->menuBar();
QMenu* fileMenu = new QMenu("&File", menus);
//I want to do something that is the equivalent of this two lines,
//but for QAction
fileMenu->setAccessibleName("File");
fileMenu->setAccessibleDescription("Alt+F");
QAction* openAction = new QAction("Open", fileMenu);
openAction->setShortcut(QKeySequence::fromString("Ctrl+O"));
fileMenu->addAction(openAction);
menus->addMenu(fileMenu);

I get something like this:
10346
|File|

|Open Ctrl+O|

And the screen reader tells me for File "File Menu Alt+F", but for Open option just "Open".

If I try and do something like:



openAction->setText(openAction->text() + " " + openAction->shortcut().toString());


I get something like this:
10347

The screen-reader tells me now "Open Ctrl+O", but as you can see it duplicates the string for shortcut.

What I've tried so far: setting all the properties that I could see (for example QAction::setWhatsThis, QAction::setIconText, etc.)

I've found a small hack that I could use; I could do something like:



openAction->setText(openAction->text() + "\n\n\n"+ openAction->shortcut().toString());

But this cuts a bit from the top of the text ("Open"). So a way to allign the text in order for it not be cut when I use this hack would do for now.
10348

I'm open to any suggestions. I think that there are ways to do this using the statusBar, but I don't know how. I hope I made myself clear... Thank you for your help! :)

anda_skoa
11th May 2014, 13:20
Good question.
This sounds like something that is not completely implemented yet. You could check the Qt issue tracker if there is an entry for that.

For now it might be necessary to implement a form of accessibility wrapper for QAction using http://qt-project.org/doc/qt-5/qaccessibleobject.html

It could also help to look into the Qt sources and check how QMenu it handles its accessibility. It might be easy to add the desired feature and submit it to the Qt project

Cheers,
_

AndreiTuicu
12th May 2014, 09:27
Thank you for your reply. :)
I've submitted a bug report. It can be found here:
https://bugreports.qt-project.org/browse/QTBUG-38915