Qt3d Input in c++
Asked Answered
O

1

4

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?

Openhanded answered 24/5, 2016 at 18:37 Comment(1)
Is this #45434565 what you are after?Uda
P
2

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]
}
Penates answered 31/5, 2018 at 7:4 Comment(2)
cd qt3d ; grep -nr . -e QMouseInput gives only src/input/frontend/qmousedevice.h:53:class QMouseInput;Ding
Saw your comment only just now, 4 years later :D None of the QML names have the leading "Q" as the C++ classes have, therefore it's only MouseInput and not QMouseInput.Penates

© 2022 - 2024 — McMap. All rights reserved.