O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required