Results 1 to 3 of 3

Thread: Problem with KeyPressEvent

  1. #1
    Join Date
    Mar 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with KeyPressEvent

    Hi,
    I have a problem with the event for Key_Space:
    my code:
    Qt Code:
    1. void MainWindow::keyPressEvent(QKeyEvent *event)
    2. {
    3. switch (event->key()) {
    4. case Qt::Key_Space: // THIS DOESNT WORK
    5. qDebug() << "space";
    6. break;
    7.  
    8. case Qt::Key_A: // THIS WORKS FINE
    9. qDebug() << "A";
    10. break;
    11. default:
    12. QWidget::keyPressEvent(event);
    13. break;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    Do you know where is the mistake. Thx

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with KeyPressEvent

    Space is typically used to select a control (like clicking it with the mouse). The tab key will act similarly.

  3. #3
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with KeyPressEvent

    You can try to installEventFilter and get the space key with it instead of keyPressEvent but I don't know if it's called before or after the Key_Space processing for the controls like squidge said

Similar Threads

  1. problem with keypressevent inside textedit
    By serula in forum Newbie
    Replies: 4
    Last Post: 28th April 2011, 13:03
  2. some problem with QLineEdit keyPressEvent
    By yxtx1984 in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2010, 09:03
  3. QLintEdit and keyPressEvent problem
    By impeteperry in forum Qt Programming
    Replies: 8
    Last Post: 2nd December 2008, 17:58
  4. keyPressEvent problem
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2008, 13:16
  5. QLineEdit keyPressEvent problem
    By impeteperry in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2007, 16:57

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