[SOLVED]Disable drag in MouseArea



  • Hi,

    I got some elements on flickable and wanted to add possibility to move that elements. Decided to use pressAndHold signal from MouseArea to activate drag but got a problem with disableing it.

    It activates really nice and after holding a finger on mouseArea it starts draging but it never disables, I mean i cannot flick on that element anymore because it drags instead of flicking flickable.

    Any suggestions how to fix it?
    Here is a part of code.

    @MouseArea{
    property bool dragActive: false
    id: mouseA
    x: 0
    y: 0
    anchors.fill: parent
    onClicked: {
    buttonClicked()
    }
    onReleased: {
    dragActive = false
    }

            onCanceled: {
                  dragActive = false
            }
            onPressAndHold: {
                  dragActive = true
            }
            drag.target: dragActive ? parent : 0
    

    }@

    Thanks in advance


  • Moderators

    Does it not work is you simply use the drag property itself, without your "dragActive" property? Like in the docs: "link":http://qt-project.org/doc/qt-5/qml-qtquick-mousearea.html#drag-prop



  • Which drag property are you refrering to?
    Because as far as I know there is no property that is responsible for disabling drag, I mean property drag.active is read only.


  • Moderators

    I mean you to try something like this:
    @
    MouseArea{
    id: mouseA
    anchors.fill: parent
    onClicked: {
    buttonClicked() // by the way, what does that function do? It may interfere with dragging
    }

    drag.target: parent
    }
    @



  • buttonClicked() is a signal to handle it later,

    and about this drag.target: parent, it will work for sure but then I won't be able to flick my area since all the signals will be received by drag. I want to enable drag only after holding(pressAndHold) a finger/mouse on the MouseArea and disable it after releasing, so after that flickArea which is the parent of my Item will receive signals.

    The problem with my code is that you cannot assign int to drag.target, so after assinging parent it won't change to 0 again(when release item), drag.target stays assing to parent


  • Moderators

    [quote author="kolegs" date="1414572563"]I want to enable drag only after holding(pressAndHold) a finger/mouse on the MouseArea and disable it after releasing, so after that flickArea which is the parent of my Item will receive signals.[/quote]

    This is exactly how drag works by default. You do not need to add any reparenting magic on your own. You can modify drag.threshold if the default does not suit you, but otherwise it should work just fine (not only should - it does, I use it in one of my apps in a similar scenario (draggable item inside a Flickable)).

    [quote author="kolegs" date="1414572563"]The problem with my code is that you cannot assign int to drag.target, so after assinging parent it won't change to 0 again(when release item), drag.target stays assing to parent[/quote]

    If you really want to, try setting it to "undefined":http://www.w3schools.com/jsref/jsref_undefined.asp.



  • After removeing dragActive property It doesn't work as I expect(I think I do sth wrong), I am dragging all items across the screen instead of flicking area, but using undefined did the magic, so I will stick to it.

    Dzięki za pomoc/Thanks for help


  • Moderators

    You're welcome mate/ nie ma sprawy :-)


Log in to reply
 

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