Handling user input
The first way of receiving events in Qt 3D is to use Qt GUI capabilities. The Qt3DQuickWindow
class we use inherits from QWindow
. That allows you to subclass Qt3DQuickWindow
and reimplement some of its virtual functions, such as keyPressEvent()
or mouseMoveEvent()
. You are already familiar with this part of Qt API because it's roughly the same as provided by Qt Widgets and Graphics View. Qt 3D doesn't introduce anything special here, so we won't give this approach much attention.
Similar to Qt Quick, Qt 3D introduces a higher-level API for receiving input events. Let's see how we can use it.
Devices
Qt 3D is focused on providing a good abstraction for every aspect it handles. This applies to input as well. In terms of Qt 3D, an application may have access to an arbitrary number of physical devices. They are represented by the AbstractPhysicalDevice
type. At the time of writing, there are two built-in types of physical devices: keyboard and mouse. You can access them by declaring...