Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Accessibility Issue with Radio Buttons in PyQt6 Setting
QtWS25 Last Chance

Accessibility Issue with Radio Buttons in PyQt6 Setting

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpython
8 Posts 3 Posters 618 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MesterPerfect
    wrote on 18 Nov 2024, 15:31 last edited by
    #1

    Hello,

    I'm encountering an accessibility issue with PyQt6 related to screen reader focus on radio buttons.

    In my application settings, I have a group of radio buttons with three options: "Enable," "Disable," and "Default." When the "Default" option is selected, I expect that navigating to this group from a previous UI element should place the screen reader's focus on the currently selected option. However, the screen reader always places its focus on the first radio button in the group, regardless of whether it is selected or not.

    Is there a way to ensure the screen reader correctly focuses on the selected radio button when entering the group?

    Thank you in advance for any advice or solutions!

    1 Reply Last reply
    1
    • M Offline
      M Offline
      MesterPerfect
      wrote on 18 Nov 2024, 15:49 last edited by MesterPerfect
      #2

      Video explaining the problem
      https://imgur.com/xTzUIJm

      import sys
      from PyQt6.QtCore import Qt
      from PyQt6.QtGui import QAction, QPalette, QColor
      from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QRadioButton, QPushButton, QWidget, QButtonGroup
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super().__init__()
              
              # Set dark theme
              self.set_dark_theme()
      
              # Create layout and central widget
              layout = QVBoxLayout()
              
              # Add example buttons before the radio buttons
              button1 = QPushButton("Button 1")
              button2 = QPushButton("Button 2")
              layout.addWidget(button1)
              layout.addWidget(button2)
              
              # Create radio buttons
              self.radio_enable = QRadioButton("Enable")
              self.radio_disable = QRadioButton("Disable")
              self.radio_default = QRadioButton("Default")
              
              # Set the "Default" option selected by default
              self.radio_default.setChecked(True)
      
              # Group the radio buttons for accessibility
              self.radio_group = QButtonGroup()
              self.radio_group.addButton(self.radio_enable)
              self.radio_group.addButton(self.radio_disable)
              self.radio_group.addButton(self.radio_default)
              
              # Add radio buttons to the layout
              layout.addWidget(self.radio_enable)
              layout.addWidget(self.radio_disable)
              layout.addWidget(self.radio_default)
              
              # Set the central widget and layout
              container = QWidget()
              container.setLayout(layout)
              self.setCentralWidget(container)
      
              self.setWindowTitle("PyQt6 Accessibility Example")
      
          def set_dark_theme(self):
              palette = QPalette()
              palette.setColor(QPalette.ColorRole.Window, QColor(53, 53, 53))
              palette.setColor(QPalette.ColorRole.WindowText, Qt.GlobalColor.white)
              palette.setColor(QPalette.ColorRole.Base, QColor(35, 35, 35))
              palette.setColor(QPalette.ColorRole.AlternateBase, QColor(53, 53, 53))
              palette.setColor(QPalette.ColorRole.ToolTipBase, Qt.GlobalColor.white)
              palette.setColor(QPalette.ColorRole.ToolTipText, Qt.GlobalColor.white)
              palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.white)
              palette.setColor(QPalette.ColorRole.Button, QColor(53, 53, 53))
              palette.setColor(QPalette.ColorRole.ButtonText, Qt.GlobalColor.white)
              palette.setColor(QPalette.ColorRole.BrightText, Qt.GlobalColor.red)
              palette.setColor(QPalette.ColorRole.Link, QColor(42, 130, 218))
              palette.setColor(QPalette.ColorRole.Highlight, QColor(42, 130, 218))
              palette.setColor(QPalette.ColorRole.HighlightedText, Qt.GlobalColor.black)
              self.setPalette(palette)
      
      app = QApplication(sys.argv)
      window = MainWindow()
      window.show()
      sys.exit(app.exec())
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 18 Nov 2024, 19:41 last edited by
        #3

        Hi,

        Are you experiencing the same issue with PySide6 ?
        Which version of PyQt6 are you using ?
        On which OS ?
        Which screen reader are you using ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply 18 Nov 2024, 20:00
        0
        • S SGaist
          18 Nov 2024, 19:41

          Hi,

          Are you experiencing the same issue with PySide6 ?
          Which version of PyQt6 are you using ?
          On which OS ?
          Which screen reader are you using ?

          M Offline
          M Offline
          MesterPerfect
          wrote on 18 Nov 2024, 20:00 last edited by
          #4

          @SGaist said in Accessibility Issue with Radio Buttons in PyQt6 Setting:

          Hi,

          Are you experiencing the same issue with PySide6 ?
          Which version of PyQt6 are you using ?
          On which OS ?
          Which screen reader are you using ?

          Hi,

          Thank you for your response.

          I'm using:

          • OS: Windows 10 Version 22H2 (OS Build 19045.5131) x64
          • Python: 3.12.7
          • PyQt6: Version 6.7.1

          I haven't tried PySide6, but I don't think testing it will solve the issue, as it seems related to how PyQt handles focus in radio button groups. I've tested this with multiple screen readers—JAWS, NVDA, and Narrator—and all of them experience the same focus issue with the selected radio button in PyQt.

          Additionally, I've noticed that PyQt has several accessibility issues, and I'm curious if the PyQt6 team is actively addressing accessibility concerns and working on fixing these issues.

          Thank you for any insight on this.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 18 Nov 2024, 21:03 last edited by
            #5

            Testing with PySide6 allows to check whether it's a binding specific or a possibly Qt specific issue.
            As for whether the PyQt folks work on this, you should as Riverbank Computing as they are the authors of that binding.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply 20 Nov 2024, 00:31
            0
            • S SGaist
              18 Nov 2024, 21:03

              Testing with PySide6 allows to check whether it's a binding specific or a possibly Qt specific issue.
              As for whether the PyQt folks work on this, you should as Riverbank Computing as they are the authors of that binding.

              M Offline
              M Offline
              MesterPerfect
              wrote on 20 Nov 2024, 00:31 last edited by
              #6

              @SGaist said in Accessibility Issue with Radio Buttons in PyQt6 Setting:

              Testing with PySide6 allows to check whether it's a binding specific or a possibly Qt specific issue.
              As for whether the PyQt folks work on this, you should as Riverbank Computing as they are the authors of that binding.

              Hi,

              I tested the same example using PySide6, and unfortunately, the focus issue remains the same. When navigating to the group of radio buttons, the screen reader still places its focus on the first button in the group instead of the selected option.

              This confirms that the problem is not specific to PyQt6 but seems to be a broader issue with how focus is handled in such scenarios.

              Looking forward to any suggestions or insights you might have.

              Thank you!

              import sys
              from PySide6.QtCore import Qt
              from PySide6.QtGui import QPalette, QColor
              from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QRadioButton, QPushButton, QWidget, QButtonGroup
              
              class MainWindow(QMainWindow):
                  def __init__(self):
                      super().__init__()
                      
                      # Set dark theme
                      self.set_dark_theme()
              
                      # Create layout and central widget
                      layout = QVBoxLayout()
                      
                      # Add example buttons before the radio buttons
                      button1 = QPushButton("Button 1")
                      button2 = QPushButton("Button 2")
                      layout.addWidget(button1)
                      layout.addWidget(button2)
                      
                      # Create radio buttons
                      self.radio_enable = QRadioButton("Enable")
                      self.radio_disable = QRadioButton("Disable")
                      self.radio_default = QRadioButton("Default")
                      
                      # Set the "Default" option selected by default
                      self.radio_default.setChecked(True)
              
                      # Group the radio buttons for accessibility
                      self.radio_group = QButtonGroup()
                      self.radio_group.addButton(self.radio_enable)
                      self.radio_group.addButton(self.radio_disable)
                      self.radio_group.addButton(self.radio_default)
                      
                      # Add radio buttons to the layout
                      layout.addWidget(self.radio_enable)
                      layout.addWidget(self.radio_disable)
                      layout.addWidget(self.radio_default)
                      
                      # Set the central widget and layout
                      container = QWidget()
                      container.setLayout(layout)
                      self.setCentralWidget(container)
              
                      self.setWindowTitle("PySide6 Accessibility Example")
              
                  def set_dark_theme(self):
                      palette = QPalette()
                      palette.setColor(QPalette.ColorRole.Window, QColor(53, 53, 53))
                      palette.setColor(QPalette.ColorRole.WindowText, Qt.GlobalColor.white)
                      palette.setColor(QPalette.ColorRole.Base, QColor(35, 35, 35))
                      palette.setColor(QPalette.ColorRole.AlternateBase, QColor(53, 53, 53))
                      palette.setColor(QPalette.ColorRole.ToolTipBase, Qt.GlobalColor.white)
                      palette.setColor(QPalette.ColorRole.ToolTipText, Qt.GlobalColor.white)
                      palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.white)
                      palette.setColor(QPalette.ColorRole.Button, QColor(53, 53, 53))
                      palette.setColor(QPalette.ColorRole.ButtonText, Qt.GlobalColor.white)
                      palette.setColor(QPalette.ColorRole.BrightText, Qt.GlobalColor.red)
                      palette.setColor(QPalette.ColorRole.Link, QColor(42, 130, 218))
                      palette.setColor(QPalette.ColorRole.Highlight, QColor(42, 130, 218))
                      palette.setColor(QPalette.ColorRole.HighlightedText, Qt.GlobalColor.black)
                      self.setPalette(palette)
              
              app = QApplication(sys.argv)
              window = MainWindow()
              window.show()
              sys.exit(app.exec())
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 30 Nov 2024, 20:07 last edited by
                #7

                Sorry I thought I answered.

                The next step would be to check the bug report system.

                If nothing shows up, please open a new report proving your reproducer script.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  friedemannkleint
                  wrote on 30 Nov 2024, 20:23 last edited by
                  #8

                  As it is an issue of the underlying Qt library unrelated to the Python bindings it would have to reported under QTBUG though ( see https://wiki.qt.io/Reporting_Bugs / https://wiki.qt.io/Qt_for_Python/Reporting_Bugs ).

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved