The code snippet you sent works fine.

The output I get when I run it:
Qt Code:
  1. before functionality
  2. your key value is 16777234
  3. inside if
  4. before functionality
  5. your key value is 16777236
  6. before box display
  7. before box display
To copy to clipboard, switch view to plain text mode 

May be make sure the proper widget is receiving the event. Rest everything is fine.