Qt3D ObjectPicker is shifted if a QtQuick Object is to the left of the Scene3D
-
I am using Qt 6.4.2 and a Scene3D in an QApplicationWindow. In the Scene3D I have an object (e.g., a Torus Mesh). I use the ObjectPicker to interact with the mesh. If there is a QtQuick Object (e.g., Rectangle) to the left of the Scene3D, the events pressed, clicked, released get triggered if the mouse is off from the mesh by the width of that element, i.e., if the mouse is to the left of the mesh by the width of the Rectangle Object. The moved event is correctly triggered, i.e., when the mouse is on top of the mesh. Is this a bug or am I doing something wrong here?
// main.qml import QtQuick import QtQuick.Controls import Qt3D.Core 2.4 import Qt3D.Render 2.4 import Qt3D.Input 2.4 import Qt3D.Extras 2.4 import QtQuick.Scene3D 2.4 ApplicationWindow { id: window width: 640 height: 480 visible: true Page { id: viewerPage width: window.width height: window.height title: "title" Row { Rectangle { width: window.width/4.0 height:window.height color:"blue" } Rectangle { id:sceneRect width: window.width/4.0*3.0 height:window.height color:"black" Scene3D { id: scene3d anchors.fill: parent focus: true aspects: ["input", "logic"] cameraAspectRatioMode: Scene3D.AutomaticAspectRatio MyEntity { id: rootEntity } } } } } }
// MyEntity.qml import Qt3D.Core 2.4 import Qt3D.Render 2.4 import Qt3D.Input 2.4 import Qt3D.Extras 2.4 import QtQuick Entity { id: sceneRoot Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 nearPlane : 0.1 farPlane : 1000.0 position: Qt.vector3d( 0.0, 0.0, 40.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) } OrbitCameraController { camera: camera } components: [ RenderSettings { id: renderSettings activeFrameGraph: ForwardRenderer { camera: camera clearColor: "red" } pickingSettings.pickMethod: PickingSettings.TrianglePicking }, InputSettings { } ] PhongMaterial { id: material diffuse: "yellow" } TorusMesh { id: torusMesh radius: 5 minorRadius: 1 rings: 100 slices: 20 } Transform { id: torusTransform scale3D: Qt.vector3d(1.5, 1, 0.5) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) } ObjectPicker { id:picker hoverEnabled: true dragEnabled:true onClicked: console.log("onClicked") onMoved: console.log("onMoved") onReleased: console.log("onReleased") onPressed: console.log("onPressed") } Entity { id: torusEntity components: [ torusMesh, material, torusTransform,picker ] } Entity { id: lightEntity components: [ pointLight, pointLightTransform] PointLight { id: pointLight } Transform { id:pointLightTransform translation: camera.position } } }
// main.cpp #include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
-
I realized that the erroneous behaviour is caused by the Page Object. The same happens if Page is replaced with Pane. However it works if one uses Control or Item instead. I hope this helps if someone encounters the same issue. Maybe it will be fixed in future Qt versions.