PDA

View Full Version : How to drag dynamic object in Qml?



Franziss
28th May 2011, 18:07
Dear all,

I seek your help in this problem which I am stucked in.

I have an icon which when I pressed it, I will create an object of it, named as iconObj. But how do I drag this newly created object? Is it possible to do this in QML? I have error when I set the drag.target: iconObj.


Image {
id: icon
width: 64
height: 64
source: "liverbird.gif"

MouseArea {
id: liverbirdMouseArea
anchors.fill: parent
width: 64
height: 64

drag.target: parent
drag.axis: Drag.XandYAxis
onPressed: {
var iconObj = Qt.createComponent("icon.qml");
iconObj.createObject(parent);
}
}
}


Thank you for your kind help.

Added after 1 38 minutes:

Is it possible to pass QMouseEvent from qml into c++?

I tried in my qml calling a c++ function cc.mousePressEvent(mouse, iconObj);



MouseArea {
id: liverbirdMouseArea
anchors.fill: parent
width: 64
height: 64

onPressed: {
var iconObj = Qt.createComponent("icon.qml");
iconObj.createObject(parent);
cc.mousePressEvent(mouse, iconObj);
}


and my c++ function is declared as follows



void cc::mousePressEvent(QMouseEvent *event, QWidget *object)
{
QDrag *drag = new QDrag(object);
}


but I get this error
Error: Unknown method parameter type: QMouseEvent*