Results 1 to 3 of 3

Thread: cant seem to catch keyboard events for key_return, key_space, key_tab, key_enter

  1. #1
    Join Date
    Aug 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default cant seem to catch keyboard events for key_return, key_space, key_tab, key_enter

    I have dialog with space and return references. I want to also be able to catch the physical keystrokes on my keyboard. everything appears to be work except for.
    key_return, key_space, key_tab, key_enter. I am focusing on key_Return not the numpad key_enter.

    the following will not trigger any event for any of the above keys.
    Qt Code:
    1. .h
    2. protected
    3. void keyPressEvent(QKeyEvent *);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. .cpp
    2. void KeyBoard::keyPressEvent(QKeyEvent *event)
    3. {
    4. qDebug()<<"event";
    5. }
    To copy to clipboard, switch view to plain text mode 

    I have also tried the following with no event trigger. all other in keystrokes are working fine.

    Qt Code:
    1. .h
    2. protected
    3. bool eventFilter(QObject *obj, QEvent *event);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. .cpp
    2. bool KeyBoard::eventFilter(QObject* obj, QEvent* event)
    3. {
    4. qDebug()<<"event";
    5. if(event->type() == QEvent::KeyPress) {
    6. QKeyEvent *key = static_cast<QKeyEvent *>(event);
    7. qDebug() << "key " << key->key() << "from" << obj;
    8. }
    9. return QObject::eventFilter(obj, event);
    10. }
    To copy to clipboard, switch view to plain text mode 

    I have been struggling with this for a couple days now.
    Last edited by swankster; 27th June 2018 at 16:11.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,387
    Thanks
    247
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: cant seem to catch keyboard events for key_return, key_space, key_tab, key_enter

    You don't tell us anything about what kind of class "Keyboard" is, nor do you say anything about where you have installed the event filter. My guess is you are either looking for events at too high a level (after a lower level widget has eaten the event) or have installed your event filter on the wrong object.

    In Qt, most widgets that capture the input focus, like buttons, line edits, etc. will eat "special" keystrokes like return, tab, and so forth, so you will never see those events at a higher level. Read the Qt Event System documentation, especially the sections on Event Handlers and Event FIlters.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Aug 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: cant seem to catch keyboard events for key_return, key_space, key_tab, key_enter

    thank you for the direction d_stranz.

    I was installing my event filter incorrectly.

Similar Threads

  1. Static compiled Qt application can not catch keyboard event
    By danielsix in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th May 2017, 14:18
  2. Catch power events (suspend, resume) on linux
    By Ginsengelf in forum Qt Programming
    Replies: 2
    Last Post: 8th April 2015, 18:55
  3. Catch maximize and restore events.
    By QT8seven in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2014, 01:56
  4. Replies: 3
    Last Post: 28th June 2012, 15:44
  5. Can I use delegate to catch mouse and keyboard events
    By hubbobubbo in forum Qt Programming
    Replies: 0
    Last Post: 29th April 2010, 12:00

Tags for this Thread

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.