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. New drag-and-drop mechanism does not work as expected in Qt-Quick
Forum Updated to NodeBB v4.3 + New Features

New drag-and-drop mechanism does not work as expected in Qt-Quick

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 3.1k 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.
  • I Offline
    I Offline
    isnot2bad
    wrote on last edited by
    #1

    I've tried to implement drag and drop in Qt 5.3 using the new QML types "Drag":http://qt-project.org/doc/qt-5/qml-qtquick-drag.html, "DragEvent ":http://qt-project.org/doc/qt-5/qml-qtquick-dragevent.html and "DropArea":http://qt-project.org/doc/qt-5/qml-qtquick-droparea.html. This is the original example from the documentation of the QML Drag type with some small modifications:

    @import QtQuick 2.2

    Item {
    width: 800; height: 600

    DropArea {
        width: 100; height: 100; anchors.centerIn: parent
    
        Rectangle {
            anchors.fill: parent
            color: parent.containsDrag ? "red" : "green"
        }
    
        onEntered: print("entered");
        onExited: print("exited");
        onDropped: print("dropped");
    }
    
    Rectangle {
        x: 15; y: 15; width: 30; height: 30; color: "blue"
    
        Drag.active: dragArea.drag.active
        // Drag.dragType: Drag.Automatic
        Drag.onDragStarted: print("drag started");
        Drag.onDragFinished: print("drag finished");
    
        MouseArea {
            id: dragArea
            anchors.fill: parent
            drag.target: parent
        }
    }
    

    }@

    Expected behaviour: The small blue rectangle (drag target) can be dragged around with the mouse. If dragged over the larger green rectangle in the center of the window, this rectangle turns red and back to green when leaving. In addition, the signals dragStarted, entered, exited, dropped and dragFinished are emitted in time and the corresponding signal handlers print out their messages.

    Experienced behaviour:

    Depends on "Drag.dragType":http://qt-project.org/doc/qt-5/qml-qtquick-drag.html#dragType-prop (see commented line #23 above):

    Drag.dragType is NOT set (default is Drag.Internal): Drag and drop works as described, but only the signals entered and exited are emitted. The other signals (dragStarted, dragFinished and dropped) are suppressed. So there is no way to react to the drop in the DropArea.

    Drag.dragType is set to Drag.Automatic: All of the signals are emitted now, but the blue rectangle (drag target) does not move with the mouse. Instead, the mouse cursor changes its shape to visualize possible drop targets. After the mouse has been released, the blue rectangle jumps to the latest mouse position.

    Neither of these two variants are pleasing. How can I get all signals and still be able to drag around the drag target? Unfortunately the documentation is everything but clear about drag-and-drop in QML, especially about the ominous Drag.dragType.

    Sidequest: Can a DropArea dynamically decline a drag/drop operation, (e.g. after inspecting the drag.source)? This does not work:
    @onEntered: drag.accepted = false@

    1 Reply Last reply
    0
    • I Offline
      I Offline
      isnot2bad
      wrote on last edited by
      #2

      I've got an "answer to this question on stackoverflow.com":http://stackoverflow.com/questions/24532317/new-drag-and-drop-mechanism-does-not-work-as-expected-in-qt-quick-qt-5-3.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Sounds that there something fishy going on either with the doc or Qt, you should bring this question to the interest mailing list. You'll find there Qt's developers/maintainers (this forum is more user oriented)

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • I Offline
          I Offline
          isnot2bad
          wrote on last edited by
          #4

          OK, thanks. This explains why I didn't get any response so far... ;)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Not necessarily, you might also have conditions that other users didn't experience so far ;)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • I Offline
              I Offline
              isnot2bad
              wrote on last edited by
              #6

              This are my greatest fears: I've got a problem and I'm the only one...worldwide... ;)

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Don't be so sure, others may have just not found out about it yet ;)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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