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. PyQt6 Creating keyboard shortcuts
Forum Updated to NodeBB v4.3 + New Features

PyQt6 Creating keyboard shortcuts

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 2.6k 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.
  • P Offline
    P Offline
    pedrovg
    wrote on last edited by
    #1

    Hi, all,

    I needed to convert my PyQt5 to PyQt6. I did not find yet a solution to define keyboard shortcuts.

    In PyQt5 I have the following code:

    self.shortcut_open = QShortcut(QKeySequence('Ctrl+O'), self)
    self.shortcut_open.activated.connect(self.getFile)
    

    I tried something like that in PyQt6, without success:

    self.button_action = QAction("Your button", self)
    self.button_action.setStatusTip("This is your button")
    self.button_action.triggered.connect(self.onMyToolBarButtonClick)
    self.toolbar.addAction(self.button_action)
    self.button_action.setShortcut(QKeySequence("Ctrl+p"))
    

    Do you have any suggestion about it?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Aliviya
      wrote on last edited by
      #2

      @pedrovg said in PyQt6 Creating keyboard shortcuts:

      I needed to convert my PyQt5 to PyQt6. I did not find yet a solution to define keyboard shortcuts.
      In PyQt5 I have the following code:
      self.shortcut_open = QShortcut(QKeySequence('Ctrl+O'), self)
      self.shortcut_open.activated.connect(self.getFile)

      I tried something like that in PyQt6, without success:
      self.button_action = QAction("Your button", self)
      self.button_action.setStatusTip("This is your button")
      self.button_action.triggered.connect(self.onMyToolBarButtonClick)
      self.toolbar.addAction(self.button_action)
      self.button_action.setShortcut(QKeySequence("Ctrl+p"))

      Unfortunately, this does not work. The solution I found is to use the QShortcut class in PyQt6, like in PyQt5:

      self.shortcut_open = QShortcut(QKeySequence('Ctrl+O'), self)
      self.shortcut_open.activated.connect(self.getFile)
      
      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