Results 1 to 2 of 2

Thread: KeyPressEvent behaves strange, skips the F key.

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default KeyPressEvent behaves strange, skips the F key.

    Hi!

    I have reimplemented the keyPressEvent to do some stuff. But I can't make it work. The purpose of the key events is to do something and then a GLWidget is supposed to be redrawn to show the result. It works with some keys, but nothing happens when sertain keys are pressed. Or at least nothing is done until I do something else that requires the GLWidget to be redrawn. When that is done, the result is shown.

    Here is some code, the F key is the one not working. The A key works just fine, also the Shift and all the rest. Maybe I haven't called setFocusPolicy ( ) correct. I've tried to insert it in the mousPressEvent(), but that didn't do anything.

    I tried to print some trace text, but that didn't come out as I hoped. Look in the code...

    Qt Code:
    1. void keyPressEvent ( QKeyEvent *event )
    2. {
    3. std::cout<<"this is not always written when a key is pressed..."<<std::endl;
    4. switch ( event->key() )
    5. {
    6. case Qt::Key_Shift:
    7. {
    8. // WORKS FINE
    9. }
    10. break;
    11.  
    12. case Qt::Key_A:
    13. {
    14. // WORKS FINE
    15. // does something ....
    16. update ( ); // updates the GLWidget
    17. }
    18. break;
    19.  
    20. case Qt::Key_F:
    21. {
    22. // THIS KEY DOESN'T WORK!
    23. focusSelection ( );
    24. update ( );
    25. }
    26. break;
    27.  
    28. default:
    29. event->ignore ( );
    30.  
    31. }// switch
    32.  
    33. }// keyPressEvent(QKeyEvent*)
    To copy to clipboard, switch view to plain text mode 

    thanks for reading
    pir

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: KeyPressEvent behaves strange, skips the F key.

    What does focusSelection() do? Could you make a minimal compilable example which reproduces the problem?

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.