Accessibility Issue with Radio Buttons in PyQt6 Setting
-
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!
-
Video explaining the problem
https://imgur.com/xTzUIJmimport 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())
-
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 ? -
@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.
-
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. -
@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())
-
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.
-
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 ).