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. Drag multiple targets at once
Forum Updated to NodeBB v4.3 + New Features

Drag multiple targets at once

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 5.0k 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.
  • F Offline
    F Offline
    Fenix Voltres
    wrote on last edited by
    #1

    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?

    When temptation brings me to my knees
    And I lay here drained of strength
    Show me kindness
    Show me beauty
    Show me truth

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shullw
      wrote on last edited by
      #2

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

      A QML Purest Point of View!

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jimon
        wrote on last edited by
        #3

        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;
        }
        }
        @

        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