PDA

View Full Version : QML MouseArea MapToItem not position the item correctly



marnando
3rd November 2014, 17:15
I have a problem with QML, I need to create a Rectangle when I do a double click on MouseArea.

The problem is that the Rectangle appears just below the mouse pointer, never in the exact position.
Can anyone tell what's wrong and how can I solve this problem.



Rectangle {
id: root
width: 360
height: 360
color: "white"

//Initial Values
property int mousePosX: 0
property int mousePosY: 0
property bool showReservoir: false

MouseArea {
id: drawArea
anchors.fill: parent
onDoubleClicked: {
var pos = mapToItem(drawArea, mouse.x, mouse.y)
drawReservoir(Math.abs(pos.x), Math.abs(pos.y))
}
}

Reservoir {
id: m_nodeReservoir
width: 60
height: 60
}

function drawReservoir(positionX, positionY)
{
m_nodeReservoir.x = positionX
m_nodeReservoir.y = positionY
m_nodeReservoir.visible = true
}
}


Thanks!!

wysota
13th November 2014, 08:15
How does "just below" manifest itself?