Results 1 to 1 of 1

Thread: How to drag dynamic object in Qml?

  1. #1

    Default Re: How to drag dynamic object in Qml?

    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.
    Qt Code:
    1. Image {
    2. id: icon
    3. width: 64
    4. height: 64
    5. source: "liverbird.gif"
    6.  
    7. MouseArea {
    8. id: liverbirdMouseArea
    9. anchors.fill: parent
    10. width: 64
    11. height: 64
    12.  
    13. drag.target: parent
    14. drag.axis: Drag.XandYAxis
    15. onPressed: {
    16. var iconObj = Qt.createComponent("icon.qml");
    17. iconObj.createObject(parent);
    18. }
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    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);

    Qt Code:
    1. MouseArea {
    2. id: liverbirdMouseArea
    3. anchors.fill: parent
    4. width: 64
    5. height: 64
    6.  
    7. onPressed: {
    8. var iconObj = Qt.createComponent("icon.qml");
    9. iconObj.createObject(parent);
    10. cc.mousePressEvent(mouse, iconObj);
    11. }
    To copy to clipboard, switch view to plain text mode 

    and my c++ function is declared as follows

    Qt Code:
    1. void cc::mousePressEvent(QMouseEvent *event, QWidget *object)
    2. {
    3. QDrag *drag = new QDrag(object);
    4. }
    To copy to clipboard, switch view to plain text mode 

    but I get this error
    Error: Unknown method parameter type: QMouseEvent*
    Last edited by Franziss; 28th May 2011 at 18:07.

Similar Threads

  1. Replies: 1
    Last Post: 20th January 2011, 18:17
  2. Replies: 2
    Last Post: 5th October 2010, 08:07
  3. Replies: 4
    Last Post: 20th August 2010, 14:07
  4. Replies: 1
    Last Post: 31st July 2010, 00:05
  5. Replies: 3
    Last Post: 10th June 2010, 16:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.