Results 1 to 3 of 3

Thread: Key Event handler

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Key Event handler

    Hi,

    I would like to ask what's the name, and how to implement, of the "press a key" event handler. I mean, what's the name of the function or how I can call that event handler and execute a code where a key or a key-combination from the keyboard is pressed.

    I have a code, inside "void FirstClass:n_actionXxxxxx_triggered(){}" which is executed when I press a button, but I'd like to execute it also when the user presses "delete" from the keyboard.

    Thanks!!!!

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Key Event handler

    Read the docs Luke.

    Seriously, this is as simple as :

    1. subclassing the widget of interest (here I assume that you know what that means)
    2. reimplementing the QWidget::keyPressEvent(QKeyEvent*) event handler
    3. doing whatever you see fit in that event handler (presumably calling your slot of choice upon press of Qt::Key_Delete and forwarding the event to the handler of the base class, again assuming you know what that means)

    If any of the terms above sound cryptic you'd save both our times by learning C++ before learning Qt as someone would say.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Mar 2009
    Posts
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Key Event handler

    First of all look up into ur code if you are any how capturing Delete key. Check if you have used :

    setShortcut(tr("Delete"));

    any where in your code.

    As this will capture Delete key on application level prevent the KeyPressEvent to capture Qt::Key_Delete. I have also faced the similar problem. The moment i commented this piece of line KeyPressEvent captured the Qt::Key_Delete. Thiswas the only possible way we were not able to capture key Qt::Key_Delete with keypressevent.

Similar Threads

  1. Deleting objects in their event handler
    By drhex in forum Qt Programming
    Replies: 7
    Last Post: 6th May 2009, 16:08
  2. Question about mouse,keyboard event handler?
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2009, 07:50
  3. Replies: 4
    Last Post: 19th February 2009, 11:10
  4. Changing default event handler name
    By mabeeh in forum Newbie
    Replies: 1
    Last Post: 21st April 2008, 15:18
  5. event handler
    By mattia in forum Newbie
    Replies: 10
    Last Post: 8th November 2007, 12:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.