Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing control+keypress instructions from one form to another

Passing control+keypress instructions from one form to another

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 304 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.
  • D Offline
    D Offline
    donquibeats
    wrote on last edited by donquibeats
    #1

    In my PyQt5 application, I've got two QDialog windows open, and the first one has a QMenuBar with various options. Some of these have keyboard shortcuts, e.g. Ctrl+S for Save, Ctrl+F for Find etc.

    If the user presses Ctrl+S or Ctrl+F while the other dialog has focus, is there any way of passing this to the first dialog, so that the save or find functions are triggered?

    I have tried doing this with passing the parameter of keyPressEvent() from the second form to keyPressEvent() on the first form, but this only seems to pass individual key values, not Ctrl+key combinations etc., so the first form gets "Ctrl" and then "S" but never a "Ctrl+S" trigger.

    Is there a way I could pass these key combination triggers to the first form, without having to code each one individually for the second form? (There are quite a few of them.)

    Pl45m4P 1 Reply Last reply
    0
    • D donquibeats

      In my PyQt5 application, I've got two QDialog windows open, and the first one has a QMenuBar with various options. Some of these have keyboard shortcuts, e.g. Ctrl+S for Save, Ctrl+F for Find etc.

      If the user presses Ctrl+S or Ctrl+F while the other dialog has focus, is there any way of passing this to the first dialog, so that the save or find functions are triggered?

      I have tried doing this with passing the parameter of keyPressEvent() from the second form to keyPressEvent() on the first form, but this only seems to pass individual key values, not Ctrl+key combinations etc., so the first form gets "Ctrl" and then "S" but never a "Ctrl+S" trigger.

      Is there a way I could pass these key combination triggers to the first form, without having to code each one individually for the second form? (There are quite a few of them.)

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @donquibeats

      Set the shortcuts' context to Qt::ApplicationShortcut.
      https://doc.qt.io/qt-5/qt.html#ShortcutContext-enum


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      3
      • D Offline
        D Offline
        donquibeats
        wrote on last edited by
        #3

        Exactly what I needed, works immediately. Thanks very much!

        Pablo J. RoginaP 1 Reply Last reply
        0
        • D donquibeats

          Exactly what I needed, works immediately. Thanks very much!

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @donquibeats said in Passing control+keypress instructions from one form to another:

          works immediately.

          great, so don't forget to mark your post as solved then!

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1

          • Login

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