Results 1 to 6 of 6

Thread: Clearing keyboard event on focusChange

  1. #1
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Clearing keyboard event on focusChange

    I've set 'L' to switch the focus from a QGraphicsView to a QListView. The problem is that as the documentation states, the Keyboard events are not cleared and therefore the list processes the keypress and jumps to the element starting with the letter L.

    How can I clear/ignore that one keypress?

    Cheers!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Clearing keyboard event on focusChange

    How do you handle the 'L' key right now?
    Some custom key event handler?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Clearing keyboard event on focusChange

    I'm using the main widget's virtual void keyReleaseEvent(QKeyEvent *e);

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Clearing keyboard event on focusChange

    Ok, I had hoped for some actual code, but providing actually useful information should not be hoped for in this time and age.
    But then again it means any suggestion can be vague as well

    Try delaying the focus change.
    Ah, heck, try calling setFocus() delayed.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Clearing keyboard event on focusChange

    Hahaha

    I could build up a MWE if necessary.

    can I still get the un-vague answer?

    The QWidget's keypressed:

    Qt Code:
    1. void ProjectForm::keyReleaseEvent(QKeyEvent *e)
    2. {
    3.  
    4. if(e->key() == Qt::Key_Q)
    5. addWaypoint();
    6. else if(e->key() == Qt::Key_L)
    7. {
    8. ui->lineView->setFocus();
    9. }
    10.  
    11. e->ignore();
    12. //e->accept();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Is that enough information?

    ...oooooorrr how do I delay the focus?


    Added after 17 minutes:


    SO I did a MWE and couldn't reproduce the issue (!) so I guess I'm using the event twice or something.

    Nevermind, I don't know if I changed something, but it ain't happening anymore.
    Last edited by quimnuss; 9th September 2015 at 12:04.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Clearing keyboard event on focusChange

    Quote Originally Posted by quimnuss View Post
    ...oooooorrr how do I delay the focus?
    Qt Code:
    1. QMetaObject::invokeMethod(ui->lineView, "setFocus", Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Keyboard event and QTextEdit
    By kaszewczyk in forum Newbie
    Replies: 2
    Last Post: 2nd November 2009, 19:30
  2. Mouse & KeyBoard Event
    By anafor2004 in forum Newbie
    Replies: 2
    Last Post: 26th October 2009, 11:39
  3. How to grad keyboard event
    By lengshuang in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2009, 13:03
  4. how to manipulate the keyboard event?
    By Ricardo_arg in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2008, 07:49
  5. Capture a keyboard event
    By mahe2310 in forum Qt Programming
    Replies: 8
    Last Post: 16th February 2006, 11:19

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
  •  
Qt is a trademark of The Qt Company.