What just happened?

In the key press event handler, we first check whether the key event was triggered because of an auto-repeat. If this is the case, we exit the function, because we only want to react on the first real key press event. Also, we do not call the base class implementation of that event handler since no item on the scene needs to get a key press event. If you do have items that could and should receive events, do not forget to forward them while reimplementing event handlers at the scene.

If you press and hold a key down, Qt will continuously deliver the key press event. To determine whether it was the first real key press or an autogenerated event, use QKeyEvent::isAutoRepeat(). It returns true if the event was automatically ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.