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. MouseArea events on a Listview Component
Forum Updated to NodeBB v4.3 + New Features

MouseArea events on a Listview Component

Scheduled Pinned Locked Moved QML and Qt Quick
15 Posts 3 Posters 4.7k Views 2 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.
  • Y Offline
    Y Offline
    Yuri
    wrote on last edited by Yuri
    #1

    Hello Community

    We have the following code below and are using a touchscreen for operation:

    import QtQuick 2.1
    import QtQuick.Window 2.0
    
    Window {
    	visible: true
    	id: box
    	width: 360
    	height: 360
    
    
    
    	ListView {
    		id: list
    		anchors.top: parent.top
    		anchors.bottom: parent.bottom
    		anchors.left: parent.left
    		anchors.right: parent.right
    		spacing: 0
    		model: 30
    		delegate: data
    		clip: true
    		focus: true
    		smooth: true
    	}
    	Component{
    		id: data
    		Item{
    			id: item
    			width: list.width
    			height: 30
    			clip: true; smooth: true; visible: true
    
    			property string cellColor: getCellColor(index)
    
    			Rectangle{
    				id: condData_item_line
    				width: parent.width
    				height: parent.height
    				color: cellColor
    				clip: true; smooth: true
    				Text{
    					text: index
    					anchors.centerIn: parent
    				}
    				MouseArea{
    					anchors.fill: parent
    					onClicked: {
    						console.log("click", index, mouse.x, mouse.y)
    					}
    					onPressed : {
    						console.log("press", index, mouse.x, mouse.y)
    					}
    					onReleased: {
    						console.log("release", index, mouse.x, mouse.y)
    					}
    					onCanceled: {
    						console.log("cancel")
    					}
    				}
    			}
    		}
    	}
    
    	function getCellColor(index){
    		var color;
    		if(index % 2 == 0){
    			color = "white";
    		}else{
    			color = "blue";
    		}
    		return color;
    	}
    }
    

    The question is the OnClicked and OnReleased events don't come up. Is this normal?
    How should it be coded so we can get the OnReleased event of the Rectangle components.

    Best Regards
    Yuri

    B 1 Reply Last reply
    0
    • Y Yuri

      Hello Community

      We have the following code below and are using a touchscreen for operation:

      import QtQuick 2.1
      import QtQuick.Window 2.0
      
      Window {
      	visible: true
      	id: box
      	width: 360
      	height: 360
      
      
      
      	ListView {
      		id: list
      		anchors.top: parent.top
      		anchors.bottom: parent.bottom
      		anchors.left: parent.left
      		anchors.right: parent.right
      		spacing: 0
      		model: 30
      		delegate: data
      		clip: true
      		focus: true
      		smooth: true
      	}
      	Component{
      		id: data
      		Item{
      			id: item
      			width: list.width
      			height: 30
      			clip: true; smooth: true; visible: true
      
      			property string cellColor: getCellColor(index)
      
      			Rectangle{
      				id: condData_item_line
      				width: parent.width
      				height: parent.height
      				color: cellColor
      				clip: true; smooth: true
      				Text{
      					text: index
      					anchors.centerIn: parent
      				}
      				MouseArea{
      					anchors.fill: parent
      					onClicked: {
      						console.log("click", index, mouse.x, mouse.y)
      					}
      					onPressed : {
      						console.log("press", index, mouse.x, mouse.y)
      					}
      					onReleased: {
      						console.log("release", index, mouse.x, mouse.y)
      					}
      					onCanceled: {
      						console.log("cancel")
      					}
      				}
      			}
      		}
      	}
      
      	function getCellColor(index){
      		var color;
      		if(index % 2 == 0){
      			color = "white";
      		}else{
      			color = "blue";
      		}
      		return color;
      	}
      }
      

      The question is the OnClicked and OnReleased events don't come up. Is this normal?
      How should it be coded so we can get the OnReleased event of the Rectangle components.

      Best Regards
      Yuri

      B Offline
      B Offline
      Buttink
      wrote on last edited by
      #2

      @Yuri I would say to try adding "preventStealing: true" to your Mouse Area. I would also double check that the listveiw has a height and width > 0.

      Y 1 Reply Last reply
      0
      • B Buttink

        @Yuri I would say to try adding "preventStealing: true" to your Mouse Area. I would also double check that the listveiw has a height and width > 0.

        Y Offline
        Y Offline
        Yuri
        wrote on last edited by
        #3

        @Buttink Putting in "preventStealing: true" somehow prevented any operation on the listview. We double checked the dimension of the listview and seem fine.

        p3c0P 1 Reply Last reply
        0
        • Y Yuri

          @Buttink Putting in "preventStealing: true" somehow prevented any operation on the listview. We double checked the dimension of the listview and seem fine.

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @Yuri Does it work properly on non touchscreen devices ?

          157

          Y 1 Reply Last reply
          0
          • p3c0P p3c0

            @Yuri Does it work properly on non touchscreen devices ?

            Y Offline
            Y Offline
            Yuri
            wrote on last edited by
            #5

            @p3c0 Tried it with a mouse and seems to work fine.

            p3c0P 1 Reply Last reply
            0
            • Y Yuri

              @p3c0 Tried it with a mouse and seems to work fine.

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @Yuri Which OS/Qt version combo are you using ?

              157

              Y 1 Reply Last reply
              0
              • p3c0P p3c0

                @Yuri Which OS/Qt version combo are you using ?

                Y Offline
                Y Offline
                Yuri
                wrote on last edited by
                #7

                @p3c0 Qt5 and Linux3.10.17

                p3c0P 1 Reply Last reply
                0
                • Y Yuri

                  @p3c0 Qt5 and Linux3.10.17

                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @Yuri Which Qt5 version and any specific Linux distro ?

                  157

                  Y 1 Reply Last reply
                  0
                  • p3c0P p3c0

                    @Yuri Which Qt5 version and any specific Linux distro ?

                    Y Offline
                    Y Offline
                    Yuri
                    wrote on last edited by
                    #9

                    @p3c0 Qt5.3.2 adn Linux is the BSP from Freescale. (The device is a freescale imx53 board)

                    p3c0P 1 Reply Last reply
                    0
                    • Y Yuri

                      @p3c0 Qt5.3.2 adn Linux is the BSP from Freescale. (The device is a freescale imx53 board)

                      p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      @Yuri Hmm then I guess it must be related to touchscreen drivers or Qt configuration. May be you should ask on FreeScale community forum.

                      157

                      Y 1 Reply Last reply
                      0
                      • p3c0P p3c0

                        @Yuri Hmm then I guess it must be related to touchscreen drivers or Qt configuration. May be you should ask on FreeScale community forum.

                        Y Offline
                        Y Offline
                        Yuri
                        wrote on last edited by
                        #11

                        @p3c0 We thought that maybe just one of the problems. We just wanted to know if there was something wrong with the way the qml file was written.

                        p3c0P 1 Reply Last reply
                        0
                        • Y Yuri

                          @p3c0 We thought that maybe just one of the problems. We just wanted to know if there was something wrong with the way the qml file was written.

                          p3c0P Offline
                          p3c0P Offline
                          p3c0
                          Moderators
                          wrote on last edited by
                          #12

                          @Yuri Who is the parent of ListView ? I just test the code with Item and Window as parents on Android phone and it works as expected.

                          157

                          Y 1 Reply Last reply
                          0
                          • p3c0P p3c0

                            @Yuri Who is the parent of ListView ? I just test the code with Item and Window as parents on Android phone and it works as expected.

                            Y Offline
                            Y Offline
                            Yuri
                            wrote on last edited by
                            #13

                            @p3c0 I have updated the OP to include everything on the file. The parent is a Window. Also we just found out that if you touch the first item(index:0), it seem to fire up click and release properly.

                            p3c0P 2 Replies Last reply
                            0
                            • Y Yuri

                              @p3c0 I have updated the OP to include everything on the file. The parent is a Window. Also we just found out that if you touch the first item(index:0), it seem to fire up click and release properly.

                              p3c0P Offline
                              p3c0P Offline
                              p3c0
                              Moderators
                              wrote on last edited by
                              #14

                              @Yuri That too works on Android. May be you should try with latest version viz. Qt 5.4.1

                              157

                              1 Reply Last reply
                              0
                              • Y Yuri

                                @p3c0 I have updated the OP to include everything on the file. The parent is a Window. Also we just found out that if you touch the first item(index:0), it seem to fire up click and release properly.

                                p3c0P Offline
                                p3c0P Offline
                                p3c0
                                Moderators
                                wrote on last edited by
                                #15

                                @Yuri Also just to make sure can you try with anchors.fill: parent instead of those 4 anchors ?

                                157

                                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