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.
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to