C ++中的Qt3d输入 [英] Qt3d Input in c++

查看:86
本文介绍了C ++中的Qt3d输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在c ++中的qt3d中处理鼠标输入?我可以使用qt3d存储库中的示例使用qml做到这一点

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

但是,没有与此等效的c ++.

There isnt a c++ equivalent for this however.

尽管进行了许多尝试(即使尝试使用附加到各种小部件的事件过滤器捕获输入),我还是无法用c ++捕获鼠标事件.这个版本的qt(5.6)是否已完成qt3d的C ++鼠标输入api,还是我应该等待5.7版?

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?

推荐答案

尽管这是一个老问题,但如果有人需要我会提供一个答案.

Although this is an old question I'll provide an answer if someone needs one.

首先,总是有与QML等效的C ++.这是因为QML只是实例化了C ++类.

First of all, there always is an equivalent of C++ to QML. This is because QML simply instantiates the C++ classes.

在这种情况下,根据 QML文档,实例化 QMouseController .

In this case, according to the QML documentation, the class QMouseController is instantiated.

查看您提供的回购中的其余代码,您必须将QMouseController创建为QEntity的子级(或者不,我认为将其设置为组件时,父级将是进行相应设置),并将其作为组件添加到所述实体.

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.

在QML代码中,此property MouseInput mouseInput仅将其作为属性添加到实体(我认为).您可能还可以省略将其添加为属性,而是为其分配一个ID(在MouseInput块内部),然后使用该ID将其添加到实体中,即

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]
}

这篇关于C ++中的Qt3d输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆