开发者

keyPressEvent() is not catching some keys on OSX

开发者 https://www.devze.com 2023-02-28 04:31 出处:网络
I am writing a program in Qt c++ and I\'m having some problem handling key press events. When run on Linux (Ubuntu 10.10) or Windows 7 the application catches these key events just fine. However when

I am writing a program in Qt c++ and I'm having some problem handling key press events. When run on Linux (Ubuntu 10.10) or Windows 7 the application catches these key events just fine. However when I run the program on OSX 10.6.7 it doesn't catch any character keys, number keys, or the arrow开发者_开发问答 keys. It does catch the caps lock, command, option, control, shift (modifier keys), but nothing else.

Is there some kind of special case of OSX that I need to handle? Perhaps a configuration? or a signal i need to connect with?

TIA


You need to set the window's focus policy to get it to accept keys.

Something like this:

QMainWindow.setFocusPolicy ( Qt::StrongFocus );

0

精彩评论

暂无评论...
验证码 换一张
取 消