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. [SOLVED]Disable drag in MouseArea
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Disable drag in MouseArea

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 7.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.
  • K Offline
    K Offline
    kolegs
    wrote on 29 Oct 2014, 07:25 last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 29 Oct 2014, 08:08 last edited by
      #2

      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

      (Z(:^

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kolegs
        wrote on 29 Oct 2014, 08:27 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 29 Oct 2014, 08:37 last edited by
          #4

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

          (Z(:^

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kolegs
            wrote on 29 Oct 2014, 08:49 last edited by
            #5

            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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 29 Oct 2014, 09:00 last edited by
              #6

              [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.

              (Z(:^

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kolegs
                wrote on 29 Oct 2014, 09:16 last edited by
                #7

                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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sierdzio
                  Moderators
                  wrote on 29 Oct 2014, 09:34 last edited by
                  #8

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

                  (Z(:^

                  1 Reply Last reply
                  0

                  1/8

                  29 Oct 2014, 07:25

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved