Results 1 to 3 of 3

Thread: keyPressEvent don't work

  1. #1
    Join Date
    Jul 2012
    Posts
    24
    Qt products
    Qt4
    Platforms
    Windows

    Default keyPressEvent don't work

    Hi,
    i have problem with keypressed
    to test my keypressed i put
    Qt Code:
    1. void myapp::keyPressEvent(QKeyEvent* evt)
    2. {
    3.  
    4. if (Qt::Key_Up)
    5.  
    6. {
    7. cout<<"i winnnnn";
    8. add_object();
    9.  
    10. emit keyPress(evt);}
    11. }
    To copy to clipboard, switch view to plain text mode 
    but even if i press another key(z,y,left...) i see "i winn" in the screen and the "add_object() method executed too

  2. #2
    Join Date
    Jul 2015
    Posts
    20
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: keyPressEvent don't work

    Think for a second. What the hell is this if statement?
    Qt Code:
    1. if(Qt::Key_Up)
    To copy to clipboard, switch view to plain text mode 
    it's literally
    Qt Code:
    1. if(0x01000013)
    To copy to clipboard, switch view to plain text mode 
    so always true.

    You surely meant
    Qt Code:
    1. if(evt.key() == Qt::Key_Up)
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2012
    Posts
    24
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: keyPressEvent don't work

    It wrk thank you

Similar Threads

  1. keyPressEvent doesn't work
    By 8Observer8 in forum Newbie
    Replies: 8
    Last Post: 27th August 2014, 05:29
  2. keypressevent dont work when MainWindow is minimized
    By spitty_cash in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2011, 16:13
  3. keypressevent
    By djwk in forum Newbie
    Replies: 9
    Last Post: 5th July 2010, 02:12
  4. QGLWidget, keyPressEvent does not work
    By ricardo in forum Qt Programming
    Replies: 7
    Last Post: 3rd July 2009, 10:28
  5. F2 keyPressEvent Not Capturing
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2007, 20:41

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.