Drag multiple targets at once



  • What's the best approach?

    In order to do that I reparent items and map their coords, but it's painful way.
    I read about QGraphicsItemGroup class, but QDeclarative Item's group setter/getter is not exposed to QML - should I do it in C++ or are there QML-ways to solve this problem?



  • I haven't tried this myself. Won't it let you set multiple drag.target: in the MouseArea?



  • just write drag proxy item, something like this :

    @
    MouseArea
    {
    id: mover; anchors.fill: parent; acceptedButtons: Qt.RightButton; drag.target = dragProxy;
    }

    Rectangle
    {
    id: testDrag1; width: 10; height:10; color:"blue"; x: 100; y:50;
    }

    Rectangle
    {
    id: testDrag2; width: 10; height:10; color:"blue"; x: 100; y:150;
    }

    Rectangle
    {
    id: dragProxy;
    width: 10; height:10; color:"red"; // make me invisible

    property variant dragObjects:[testDrag1, testDrag2];

    property int lastX;
    property int lastY;

    onXChanged:
    {
    var deltaX = x - lastX;
    for(var i = 0; i < dragObjects.length; ++i)
    dragObjects[i].x += deltaX;
    lastX = x;
    }

    onYChanged:
    {
    var deltaY = y - lastY;
    for(var i = 0; i < dragObjects.length; ++i)
    dragObjects[i].y += deltaY;
    lastY = y;
    }
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.