Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get 3D coordinate of mouse position from onClicked in QML
Qt 6.11 is out! See what's new in the release blog

Get 3D coordinate of mouse position from onClicked in QML

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nuts1221stun
    wrote on last edited by
    #1

    I created a 3D room by using Quad in QML.
    It looks like this, view from the top
    !http://www.csie.ntu.edu.tw/~r00944015/room.jpg(3D room)!

    I would like to implement the "add furniture" function. When I click on the ground of the room, a table will appear at the clicked spot. That means I would have to get the 3D coordinate of the mouse position. But when I try something like
    @Quad {
    id: ground
    scale: room.scale
    effect: Effect {
    color: "#ffffff"
    decal: true
    }
    transform: [
    Rotation3D {
    angle: 90
    axis: Qt.vector3d(1, 0, 0)
    },
    Rotation3D {
    angle: 90
    axis: Qt.vector3d(0, 1, 0)
    },
    Rotation3D {
    angle: 90
    axis: Qt.vector3d(0, 0, 1)
    }
    ]
    onClicked: {
    console.log("click on ground!");
    console.log(mouse.x);
    }
    }@

    The text "click on ground!" is successfully printed. But mouse.x cannot be displayed because it always says "ReferenceError: mouse is not defined"

    I checked http://blog.gmane.org/gmane.comp.lib.qt.3d/month=20120501 , and back then there was no provided solution in the QML API. I wonder if the 3D coordinates can be acquired through QML API now. If not, is there other possible implementation?
    Also is it possible to detect mouse event on the background (i.e. the black background in the image)? Or should I just add a large Quad in the back of the room...

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved