Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139719

a11y: Label buddy misses labelled-by relation if it's not a sibling

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.11.0 FF
    • 6.11.0 FF
    • None
    • Debian trixie, qtbase self-compiled from git dev as of commit a4c7885e8b918385a74142de894357d259d7d1b8
    • Linux/Wayland, Linux/X11
    • 99a10f452 (dev)

      A QLabel can be set to label another widget using QLabel::setBuddy.
      This not only allows moving keyboard focus to the buddy widget by pressing the label's accelerator key, but also sets the accessible labelled-by relation (e.g. ATSPI_RELATION_LABELLED_BY for Linux/AT-SPI: https://gnome.pages.gitlab.gnome.org/at-spi2-core/libatspi/enum.RelationType.html#labelled_by for the buddy widget's accessible object. This is e.g. needed for screen readers to announce the label text when the buddy widget receives focus.

      However, the accessible relation is currently only set if the buddy is a sibling of the label, not otherwise.

      It should also work when the label and its buddy are not siblings.

      Sample steps to reproduce on Linux:

      1. Compile and run the sample program below
      2. start Accerciser and select the line edit's accessible object in Accerciser's treeview of the sample program's a11y tree
      3) In Accerciser's Interface Viewer, check the relations for the selected object
      -> None are shown
      4) to double-check: query the relations using Accerciser's IPython console:

      In [1]: acc.get_relation_set()
      Out[1]: []
      

      Actual result:

      No relations are visible in steps 3 or 4.

      Expected result:
      A labelled-by relation should exist to the "My Label" label, as that one has the line edit set as its mnemonic widget.
      As mentioned before, this works if both widgets are siblings.

      Sample application:

      #include <QApplication>
      #include <QMainWindow>
      #include <QVBoxLayout>
      #include <QLabel>
      #include <QLineEdit>
      
      int main(int argc, char* argv[])
      {
          QApplication a(argc, argv);
          QMainWindow w;
          QWidget* widget = new QWidget(&w);
          w.setCentralWidget(widget);
      
          QVBoxLayout* layout1 = new QVBoxLayout(widget);
      
          QWidget* widget2 = new QWidget(widget);
          layout1->addWidget(widget2);
          QVBoxLayout* layout2 = new QVBoxLayout(widget2);
          QLabel* label = new QLabel("My Label", widget);
          layout2->addWidget(label);
      
          QWidget* widget3 = new QWidget(widget);
          layout1->addWidget(widget3);
          QVBoxLayout* layout3 = new QVBoxLayout(widget3);
          QLineEdit* lineEdit = new QLineEdit(widget3);
          layout3->addWidget(lineEdit);
      
          label->setBuddy(lineEdit);
      
          w.show();
          return a.exec();
      }
      
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            michaelweghorn Michael Weghorn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes