Search code examples
qtaccessibilityqlistwidget

QListWidget working as a menu - need to be able to activate menu options using number keys rather than just getting focus


This application is for accessibility so will be used by blind/visually impaired users amongst others. So it has a listWidget on the screen disguised as a menu using style sheets. The functionality behind each item on the list needs to be accessed in the following ways: – mouse click – up and down arrows to select then hit return key – number key (voice says “press 1 for email” etc) – hands free voice activation – Braille input

the last two I have not got to yet because I am failing to get the first 3 working (I can get all of them working but not all at the same time, fixing one breaks another). The listWidget already processes number keys (if you press 4 the 4th row gets selected – I need pressing 4 to run the menu item functionality without a second user input) but I am just missing something in how it works.

Is this something I just need to do with different object?


Solution

    1. For mouse click, I think it's straightforward to implement menu functionalities in respective clickevents of widgets in listwidget.

    2. Use keyPressEvent(QKeyEvent *); to process up, down and return keys in combination with listwidget->hasFocus() if needed.

    3. Use the same keyPressEvent(QKeyEvent *); to process number keys.