Keyboard input

So far, we've been dealing with pointer input, but user input is not just that—we can also handle keyboard input. This is quite simple and basically boils down to two easy steps.

First, you have to enable receiving keyboard events by stating that a particular item has keyboard focus:

focus: true 

Then, you can start handling events by writing handlers in a similar fashion as for mouse events. However, Item doesn't provide its own handler for manipulating keys that is a counterpart for keyPressEvent and keyReleaseEvent of QWidget. Instead, adequate handlers are provided by the Keys attached property.

Attached properties are provided by elements that are not used as standalone elements but provide properties to other objects ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.