Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-82653

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.1
    • Qt3D
    • None
    • macOS

    Description

      I have a Scene3D where I dynamically add an entity which has an ObjectPicker, via this helper class' Scene3DViewHelper::addCuboid() slot:

      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() << "c++: 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 ObjectPicker doesn't work: I'm supposed to see the "clicked entity Qt3DCore::QEntity(0x7fa19f005300)" message on the console when I click the cuboid, but I don't see it.

      If I uncomment the `cuboid0` entity, then picking works both for the `cuboid0` entity and for the dynamically created cuboid:

      qml: clicked entity Qt3DCore::Quick::Quick3DEntity(0x7fa0d7c025e0)
      c++: clicked entity Qt3DCore::QEntity(0x7fa0d6527f10)
      

      Note that this bug happens only when hoverEnabled is set to true.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mkrus Mike Krus
            ff Federico Ferri
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes