Qt3d Input in c++

放肆的年华 提交于 2019-12-10 17:35:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!