[Interest] Qt3D ObjectPicker doesn't work for a dynamically created entity if there isn't already another entity with ObjectPicker

Federico Ferri federico.ferri.it at gmail.com
Tue Mar 3 18:30:35 CET 2020


I’m dynamically creating a Qt3D entity via C++

    if(!rootEntity_) return;
    auto cuboidEntity = new Qt3DCore::QEntity(rootEntity_);
    auto mat = new Qt3DExtras::QPhongMaterial(cuboidEntity);
    mat->setDiffuse(QColor(217, 217, 255));
    auto t = new Qt3DCore::QTransform(cuboidEntity);
    auto mesh = new Qt3DExtras::QCuboidMesh(cuboidEntity);
    auto picker = new Qt3DRender::QObjectPicker(cuboidEntity);
    connect(picker, &Qt3DRender::QObjectPicker::clicked, [=] {
        qDebug() << "clicked entity" << cuboidEntity;
    });
    mesh->setXExtent(1);
    mesh->setYExtent(1);
    mesh->setZExtent(1);
    cuboidEntity->addComponent(mat);
    cuboidEntity->addComponent(t);
    cuboidEntity->addComponent(mesh);
    cuboidEntity->addComponent(picker);

the problem is that the object picker doesn’t seem to work.
However, if the scene tree has already a static (declared in QML) entity
with an ObjectPicker in it, then picking works both in the static entity
and in my dynamically created entity.

Is this a bug or am I doing something wrong?

This has been asked also on
https://stackoverflow.com/questions/60509246/objectpicker-doesnt-work-for-a-dynamically-created-entity-if-there-isnt-alread
with
more exhaustive code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200303/04471739/attachment.html>


More information about the Interest mailing list