Results 1 to 2 of 2

Thread: F2 keyPressEvent Not Capturing

  1. #1
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default F2 keyPressEvent Not Capturing

    In my main application window (QMainWindow), I am capturing the keyPressEvent for all the Function keys. I am successfully capturing F1, F3-F12, but F2 will not cause a keyPressEvent. I have looked throughout my main window code and I am not using F2 for any other shortcut that I know of. The thing that really has me puzzled is that I am creating a second QMainWindow and capturing the F1-F12 keyPressEvents without any problem. Is there some default shortcut that uses F2 that I am missing? I have ensured that I am using accept( )/ignore( ) throughout the press event.

    Qt Code:
    1. void MainWindow::keyPressEvent( QKeyEvent *event )
    2. {
    3. //This line will print for every key other than F2
    4. fprintf( stderr, "In MainWindow::keyPressEvent( QKeyEvent *event )" );
    5.  
    6. QString keySequence = "";
    7.  
    8. if( event->state( ) & Qt::ControlButton )
    9. {
    10. keySequence += tr( "Ctrl+" );
    11. }
    12. if( event->state( ) & Qt::ShiftButton )
    13. {
    14. keySequence += tr( "Shift+" );
    15. }
    16. if( event->state( ) & Qt::AltButton )
    17. {
    18. keySequence += tr( "Alt+" );
    19. }
    20. if( event->state( ) & Qt::MetaButton )
    21. {
    22. keySequence += tr( "Meta+" );
    23. }
    24.  
    25. if( event->key( ) != Qt::Key_Control &&
    26. event->key( ) != Qt::Key_Shift &&
    27. event->key( ) != Qt::Key_Meta &&
    28. event->key( ) != Qt::Key_Alt )
    29. {
    30. ... continue building the keySequence and check against configuration file
    31. }
    32.  
    33. event->ignore( );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Talking Re: F2 keyPressEvent Not Capturing

    I think I have found the solution to your problem. If you follow this link http://trolltech.com/developer/notes...changes-3.3.8/ you will see there was a problem with capturing F2 in QTables that they had some problems. Do you have a QTable in your main window? If so try subclassing the QTable and ignore the key press event at least for the F2 key so it goes up to your main window. Let me know if this helps and if it does not I will look for other ideas.

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. keyPressEvent problem
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2008, 13:16
  3. Capturing Key_up and Key_down for QTreeView
    By forrestfsu in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2007, 16:44
  4. Handling of dead keys in keyPressEvent()
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2006, 12:26
  5. KeyPressEvent behaves strange, skips the F key.
    By pir in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2006, 17:07

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.