问题
Is it possible to do handle mouse input in qt3d in c++? I am able to do so using qml using a sample in the qt3d repo
https://github.com/qtproject/qt3d/tree/5.6/examples/qt3d/mouseinput-qml
There isnt a c++ equivalent for this however.
I am not able to do capture mouse events in c++ at all despite numerous attempts (even trying to capture input using event filters attached to various widgets) . Is the c++ mouse input api for qt3d complete for this version of qt (5.6) or should i wait for version 5.7?
回答1:
Although this is an old question I'll provide an answer if someone needs one.
First of all, there always is an equivalent of C++ to QML. This is because QML simply instantiates the C++ classes.
In this case, according to the QML documentation, the class QMouseController is instantiated.
Looking at the rest of the code in the repo you provided, you have to create the QMouseController
as a child of the QEntity
(or don't, I think when setting it as a component the parent will be set accordingly as well) and add it as a component to said entity.
This property MouseInput mouseInput
in the QML code only adds it as an attribute to the entity (I assume). You could probably also omit adding it as an attribute and instead assign it an ID (inside the MouseInput
block) and use this ID to add it to the entity, i.e.
Entity {
id: sphere1
MouseInput {
id: mouseInput
controller: mouseController
}
components: [mouseInput]
}
来源:https://stackoverflow.com/questions/37421388/qt3d-input-in-c