Home > Blockchain >  Accessibility notification in Qt
Accessibility notification in Qt

Time:03-26

I am trying to push notification to Jaws or NVDA when certain events occur. These events can occur any time and any application widget can have the focus. They are not linked to user actions but to the controller events. This is my try:

void announceNewMessageIfNeeded(){
    if(QAccessible::isActive()){
         QWidget* focusWidget = QApplication::focusWidget();
         if(focusWidget != nullptr){
              auto* accessibleInterface = QAccessible::queryAccessibleInterface(focusWidget);
              accessibleInterface->setText(QAccessible::Name, "New Message");
              auto *ev = new QAccessibleEvent(accessibleInterface, QAccessible::Alert);
              QAccessible::updateAccessibility(ev); 

         }
    }
}

I tried the above code with various little changes but I either do not have accesibility update or undesired access to nullpointers. With debug logs, I know for sure that the focusWidget is correct (it points to the item having the currentFocus) and that announceNewMessageIfNeeded is called. Any idea?

CodePudding user response:

solution that seems to work:

if(QAccessible::isActive()){
    QWidget* focusedWidget = QApplication::focusWidget();
    if(focusedWidget != nullptr){
        auto *ev =  new QAccessibleValueChangeEvent(focusedWidget, "New Message");
        QAccessible::updateAccessibility(ev);
    }
}
  • Related