某段程序中发现重载keyPressEvent后不能收到方向键的响应。查看qt说明文档:
This event handler, for event event, can be reimplemented in a subclass to receive key press events for the widget.
A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.
即:加上 setFocusPolicy()。
另一种方法:
重载keyReleaseEvent事件处理。