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. action to be triggered based on its custom shortcut

action to be triggered based on its custom shortcut

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 401 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    suppose i have some action to happen. for that i can create an QAction object and connect its triggered signal to the slot that executes the desired function. also, i can have a shortcut associated with the action; changing the shortcut i'll be able to execute the same action with that shortcut.

    my problem now is that the "shortcut" i wanna set to the action, contains also a mouse button press (and mouse events cannot be assigned to action shortcuts); say i want Shift+Left mouse button. maybe this sounds a little bit harsh but bear with me.

    what do i need? well, i have a button, and an action (say "execute a script"). i want the script to execute when Shift+Left click is clicked, and i want this "shortcut" to be customized, i.e. the user should be able to change to shortcut to, say Ctrl+Left click (from some gui element, e.g. button text), and now Ctrl+Left click should execute the script.

    how can i do this?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi
      Well the shortcut system cannot be tied to mouse events so you have to make a special launch button
      that has a overwritten mousePress function.
      In that function you can use
      http://doc.qt.io/qt-5/qguiapplication.html#queryKeyboardModifiers
      to see if ctrl, shift , alt is pressed and then emit a signal to have the
      script holder execute the script.

      For editing it, you can use a line edit and let user somehow select the keys and mouse button.
      (maybe from comboboxes )

      [edit: fixed typo SGaist]

      1 Reply Last reply
      2

      • Login

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