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. Shortcuts and widget keyPressEvent
Forum Updated to NodeBB v4.3 + New Features

Shortcuts and widget keyPressEvent

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 408 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rwilliams
    wrote on last edited by rwilliams
    #1

    Hello,

    I'm trying to figure out how to override a key shortcut. The delete key press should have different behavior if a particular widget has focus. The overloaded keyPressEvent isn't called for that derived widget because it is getting channeled to a shortcut action. If the shortcut action is disabled then the keyPessEvent is called as expected. I'm hoping there is a cleaner way than trying to manage the shortcut enable.

    TIA

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Hi;
      First thing that comes in mind is to install an event filter and to intercept QEvent::ShortcutOverride:

      bool SomeWidget::eventFilter(QObject *obj, QEvent *event)
      {
      	if(event->type() == QEvent::ShortcutOverride)
              {
              ...
              }
      
      1 Reply Last reply
      1
      • R Offline
        R Offline
        rwilliams
        wrote on last edited by
        #3

        Thanks, that appears to be the solution. I install the event filter in the widget's constructor and trap the shortcut delete key in the event filter method. Then accept the event, do the widget's specific handling, and then return true.

        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