Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML mouse pressed and onEntered

QML mouse pressed and onEntered

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.5k Views
  • 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.
  • S Offline
    S Offline
    sharethl
    wrote on 12 Jun 2015, 14:09 last edited by sharethl
    #1

    How can I pressed mouse and move into a mouse area, and this mouse area could run onEntered?

    With current code, once I press and hold on buttonMouseArea 1, and move mouse to another buttonMouseArea 2, Area 2 will not response onEntered.

    Thanks

        MouseArea {
            id: buttonMouseArea
            anchors.fill: parent
            hoverEnabled: true
            onEntered: console.log(txt.text);
    
            //        onClicked: root.clicked()
            //        onPressed: alternatesRow.visible = true // enable buble effect
            //        onReleased: alternatesRow.visible = false // enable buble effect
        }
    
    P 1 Reply Last reply 13 Jun 2015, 04:55
    0
    • S sharethl
      12 Jun 2015, 14:09

      How can I pressed mouse and move into a mouse area, and this mouse area could run onEntered?

      With current code, once I press and hold on buttonMouseArea 1, and move mouse to another buttonMouseArea 2, Area 2 will not response onEntered.

      Thanks

          MouseArea {
              id: buttonMouseArea
              anchors.fill: parent
              hoverEnabled: true
              onEntered: console.log(txt.text);
      
              //        onClicked: root.clicked()
              //        onPressed: alternatesRow.visible = true // enable buble effect
              //        onReleased: alternatesRow.visible = false // enable buble effect
          }
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 13 Jun 2015, 04:55 last edited by
      #2

      @sharethl What is wrong with your current code ?

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sharethl
        wrote on 15 Jun 2015, 14:54 last edited by
        #3

        @p3c0 With current code, once I press and hold on buttonMouseArea 1, and move mouse to another buttonMouseArea 2, Area 2 will not response.

        P 1 Reply Last reply 16 Jun 2015, 05:45
        0
        • S sharethl
          15 Jun 2015, 14:54

          @p3c0 With current code, once I press and hold on buttonMouseArea 1, and move mouse to another buttonMouseArea 2, Area 2 will not response.

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 16 Jun 2015, 05:45 last edited by
          #4

          @sharethl AFAIK it doesn't trigger if the area under mouse changes while the mouse is still pressed. Some info here. BTW, are you trying to do drag-drop kind of thing ?

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sharethl
            wrote on 18 Jun 2015, 19:36 last edited by
            #5

            @p3c0 I am actually doing QML keyboard. User pressed on wrong key, they want to press and hold move to another key and release.

            P 1 Reply Last reply 19 Jun 2015, 07:45
            0
            • S sharethl
              18 Jun 2015, 19:36

              @p3c0 I am actually doing QML keyboard. User pressed on wrong key, they want to press and hold move to another key and release.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 19 Jun 2015, 07:45 last edited by
              #6

              @sharethl Well in that case you can keep MouseArea as a parent item which will contain all other item i.e in your case keyboard keys. Then you can use onPressed and onReleased signal handlers where in you can get the exact child using childAt .
              Consider the following example:

              import QtQuick 2.4
              
              Item {
                  width: 140
                  height: 100
                  MouseArea {
                      anchors.fill: parent
                      onPressed: console.log(childAt(mouseX,mouseY).objectName)
                      onReleased: console.log(childAt(mouseX,mouseY).objectName)
                      Rectangle {
                          objectName: "Rect1"
                          width: 50
                          height: 50
                          color: "red"
                      }
                      Rectangle {
                          objectName: "Rect2"
                          x:50
                          width: 50
                          height: 50
                          color: "green"
                      }
                  }
              }
              

              157

              S 1 Reply Last reply 19 Jun 2015, 20:06
              0
              • P p3c0
                19 Jun 2015, 07:45

                @sharethl Well in that case you can keep MouseArea as a parent item which will contain all other item i.e in your case keyboard keys. Then you can use onPressed and onReleased signal handlers where in you can get the exact child using childAt .
                Consider the following example:

                import QtQuick 2.4
                
                Item {
                    width: 140
                    height: 100
                    MouseArea {
                        anchors.fill: parent
                        onPressed: console.log(childAt(mouseX,mouseY).objectName)
                        onReleased: console.log(childAt(mouseX,mouseY).objectName)
                        Rectangle {
                            objectName: "Rect1"
                            width: 50
                            height: 50
                            color: "red"
                        }
                        Rectangle {
                            objectName: "Rect2"
                            x:50
                            width: 50
                            height: 50
                            color: "green"
                        }
                    }
                }
                
                S Offline
                S Offline
                sharethl
                wrote on 19 Jun 2015, 20:06 last edited by
                #7

                @p3c0 Nice. But I have nested layout, and Key are in the most bottom level. How can I use childAt() find it out?

                Column{
                   Repeater{
                      Row{
                          Repeater{
                               KeyDelegate
                          }  
                      }
                  }
                }
                
                P 1 Reply Last reply 20 Jun 2015, 06:32
                0
                • S sharethl
                  19 Jun 2015, 20:06

                  @p3c0 Nice. But I have nested layout, and Key are in the most bottom level. How can I use childAt() find it out?

                  Column{
                     Repeater{
                        Row{
                            Repeater{
                                 KeyDelegate
                            }  
                        }
                    }
                  }
                  
                  P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 20 Jun 2015, 06:32 last edited by
                  #8

                  @sharethl If the order of nesting is fixed then you can chain childAt method.
                  Alternatively you can may be use GridView. It has a similar method called itemAt. The advantage in this case is you can directly call that method using GridView's id.

                  157

                  S 1 Reply Last reply 25 Jun 2015, 17:31
                  0
                  • P p3c0
                    20 Jun 2015, 06:32

                    @sharethl If the order of nesting is fixed then you can chain childAt method.
                    Alternatively you can may be use GridView. It has a similar method called itemAt. The advantage in this case is you can directly call that method using GridView's id.

                    S Offline
                    S Offline
                    sharethl
                    wrote on 25 Jun 2015, 17:31 last edited by
                    #9

                    @p3c0 Got it working.

                    use nested for loop to go through column and row, to find keys.
                    Thank you!

                    MouseArea{
                                anchors.fill: parent
                                onMousePositionChanged: {
                                    var row = column.childAt(mouseX, mouseY);
                                    // clear all bubbles
                                    for (var i = 0; i < column.children.length; i++) {
                                        var r = column.children[i];
                                        for(var j=0; j < r.children.length; j++){
                                            if(r.children[j].objectName==="KeyButton"){
                                                r.children[j].bubleVisible=false;
                                            }
                                        }
                                    }
                                    if(row === null){
                                        return;
                                    }
                                    var key = row.childAt(mouseX,5); // relative use any number 0 to height of key
                                    if(key !== null && key.objectName=== "KeyButton"){
                                        key.bubleVisible=true;
                                    }
                                }
                                onReleased: {
                                    var row = column.childAt(mouseX, mouseY);
                                    var key = row.childAt(mouseX,5); // relative use any number 0 to height of key
                                    if(key !== null ){
                                        key.bubleVisible= false;
                                        console.log(key.text);
                                    }
                                }
                            }
                    
                    1 Reply Last reply
                    0

                    8/9

                    20 Jun 2015, 06:32

                    • Login

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