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. OnEntered during mouse drag

OnEntered during mouse drag

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

    Hello,

    Please teach me how to make an onEntered event happen while I'm dragging movableObject.

    I wrote the following code:
    @import QtQuick 2.0

    Rectangle {
    id: window
    width: 200
    height: 200

    Rectangle {
        id: movableObject
        width: 50; height: 50
        border.color: "black"
    
        MouseArea {
            anchors.fill: parent
            drag.target: parent
        }
    }
    
    Rectangle {
        id: hoverArea
        x: 100; y: 100;
        width: 50; height: 50
        border.color: "blue"
    
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onEntered: {
                console.log("entered"); // this event doesn't happen while I'm dragging movableObject.
            }
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hykkel
      wrote on last edited by
      #2

      Shouldn't the drag.target on line 15 be movableObject? Do not know if it helps?

      EDIT: No parent should be fine

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uchan
        wrote on last edited by
        #3

        Thanks for your reply, Hykkel.

        If I delete the line 15, movableObject will not be able to drag.
        I think I have to set movableObject to drag.target.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hykkel
          wrote on last edited by
          #4

          Hi.

          I was looking for something else, when I stumbled across this. Maybe you can make a workaround using states and containsMouse (see e.g. last codeexample).

          http://qt-project.org/doc/qt-4.8/qml-behaviors-and-states.html

          It may not be the best solution, but maybe you can get it working.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            uchan
            wrote on last edited by
            #5

            Thanks Hykkel

            I checked the article and wrote code below.
            I added states attribute but myEntered() is not called during dragging movableObject.
            (When a mouse enters hoverAreaMouser without dragging, myEntered() is called.)
            @import QtQuick 2.0

            Rectangle {
            id: window
            width: 200
            height: 200

            Rectangle {
                id: movableObject
                width: 50; height: 50
                border.color: "black"
            
                MouseArea {
                    anchors.fill: parent
                    drag.target: parent
                }
            }
            
            Rectangle {
                x: 100; y: 100;
                width: 50; height: 50
                border.color: "blue"
            
                MouseArea {
                    id: hoverAreaMouser
                    anchors.fill: parent
                    hoverEnabled: true
                    function myEntered() {
                        console.log("entered");
                    }
                }
            
                states: State {
                    when: hoverAreaMouser.containsMouse
                    StateChangeScript {
                        script: hoverAreaMouser.myEntered();
                    }
                }
            }
            

            }@

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hykkel
              wrote on last edited by
              #6

              Weird!

              Hoped the workaround might have worked.

              The mouse event seems to be suppressed (like when using propagateComposedEvents: or preventStealing:). Perhaps this is the issue? I'm afraid we need some expert on this... it's probably some simple setting. A bug like this would have been caught - right?

              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