I'm trying to implement a settings menu which should open on pressing keys of ctrl+, of the standard US layout on any layout. But on non-US layout it opens on different keys. Is there a way to achieve this?
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
menubar = self.menuBar()
file_menu = menubar.addMenu("File")
settings_action = QAction("Preferences", self)
settings_action.setMenuRole(QAction.MenuRole.PreferencesRole)
settings_key = QKeySequence(QKeySequence.StandardKey.Preferences)
if not settings_key.toString():
settings_key = QKeySequence("Ctrl+,")
settings_action.setShortcut(settings_key)
settings_action.triggered.connect(lambda: print("Opened"))
file_menu.addAction(settings_action)
if __name__ == "__main__":
app = QApplication()
window = MainWindow()
window.show()
app.exec()