[Interest] How to select objects with Qt3D? (QMouseHandler question)

Edward Moyse Edward.Moyse at cern.ch
Wed Jul 6 13:47:54 CEST 2016


Fantastic! Thanks!

On 06 Jul 2016, at 12:44, Sean Harmer <sean.harmer at kdab.com<mailto:sean.harmer at kdab.com>> wrote:

Hi,

the easiest way is to use a QObjectPicker component on your entity. By default this uses raycast picking against the bounding sphere of your entity's mesh. If this is not precise enough for you, you can enable triangle-ray intersection testing by way of the QRenderSettings or you can attach your object picker to a child entity with a smaller mesh.

Cheers,

Sean

On 06/07/2016 09:26, Edward Moyse wrote:
Hi all,

I’m trying to play with Qt3d (in Qt5.7), and I'm struggling with the lack of documentation and/or tutorials (and so I apologise in advance if this is an obvious question).

What I wanted to test is how easy it is to click in the 3D view and select an object.

If I understand correctly, I should do this using a QMouseHandler and add this to the entity.

To test this, I modified the basic shapes example as follows:

in the initialisation list of SceneModifier I added:

      m_mouseDevice(new Qt3DInput::QMouseDevice()),

      m_mouseHandler(new Qt3DInput::QMouseHandler())

and in the rest of the ctor it now looks like:

 m_mouseHandler->setSourceDevice(m_mouseDevice);

    // Sphere

    m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);

    m_sphereEntity->addComponent(sphereMesh);

    m_sphereEntity->addComponent(sphereMaterial);

    m_sphereEntity->addComponent(sphereTransform);

    m_sphereEntity->addComponent(m_mouseHandler);

//    QObject::connect(mouseHandler, SIGNAL(clicked(Qt3DInput::QMouseEvent*)),

//                     this, SLOT(clicked(Qt3DInput::QMouseEvent*)));

    QObject::connect(m_mouseHandler, &Qt3DInput::QMouseHandler::clicked,

                     this, &SceneModifier::clicked);

And I also added a new method:

void SceneModifier::clicked(Qt3DInput::QMouseEvent* event)

{

    qDebug() << "clicked!";

}

However the function never gets called - I suspect I’ve missed something very obvious, but if so I’d really appreciate any tips and/or links to anything else to read.

Cheers,

Ed




_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest


_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160706/bccaa839/attachment.html>


More information about the Interest mailing list