Qt3D point and line picking?

  • Hi there, I've been trying to do point and line picking on a mesh in Qt3D. Here's a working version of triangle picking,

    auto renderSettings = new Qt3DRender::QRenderSettings(root);
    auto entity = new Qt3DCore::QEntity(root);
    auto picker = new Qt3DRender::QObjectPicker;
    auto sphere = new Qt3DExtras::QSphereGeometry;
    connect(picker, &Qt3DRender::QObjectPicker::clicked, [](Qt3DRender::QPickEvent* e) {
        auto p = dynamic_cast<Qt3DRender::QPickTriangleEvent*>(e);
        auto idx = p->triangleIndex();

    However, when I switched to point picking or line picking, the clicked event is never triggered. Any idea how to make this work? Thanks in advance.

  • Banned

    This post is deleted!

  • Hi @unclejimbo-0 ,

    in my experience, Line and Point Picking doesn't works on Qt5.9, but tested and functionnal on Qt5.12.

    The main reason why you can't pick lines or points is that yout entity is NOT a Line or a Point. Actually, your entity represent a Sphere which is composed of triangles only. Thus, no line or point picking available.

    if you want to perform Line Picking, I recommend you to start from the custom-mesh example :


    and adapt it draw lines. Once vertices and indices modified, simply change the MeshRenderer primitive types to Line

    // From
    // To

    Then, in the render settings set


    and add your QObjectPicker component to your custom Mesh.

    It should be working. If not working properly, try to increase the picking tolerance

    renderSettings->pickingSettings()->setWorldSpaceTolerance(10.0f); // default is 0.1f

    This last parameter is tricky as long as it performs tolerance checking in the world space rather than Screen space. Thus, if the camera is really close to the line, it will be easy to intersect. However, as long as you get farther, it gets difficult to pick lines due to pixel to ray resolution.

    Hope it helps.

  • @lcadet Hi, thank you for your reply.

    I believe you are right. Although I ended up not doing lines or points picking, but I think your explanation is the right way to go.

    One more thing I think might be important for picking is that you need to set the vertex count properly. It's quite confusing that Qt3D can render the geometry correctly even without calling QAttribute::setCount, as long as you call QGeometryRenderer::setVertexCount. I've dug the qt3d source code a bit and I think they have a way of guessing the vertex count upon rendering, based on the counts you've provided. However, the picking process seems to merely counting on the count set in QAttribute. And if you forget to set it, the picking will fail even for triangles.

    So, that's basically my experience so far. I hope qt3d could provide better documentation and more intuitive APIs.

  • Hope that it could help someone.
    Did you try this strategy ? If so and if it solved your problem, could you set the topic as solved ?
    I think it could help other people who is looking for it :-)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.