Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QML Listview onClick event(solved)

    QML and Qt Quick
    3
    7
    5203
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by

      Hi all,

      I have used itemAt(mouseX, mouseY) for getting the clicked buttons inside QML listview. It works fine, but when i scroll the listView to bottom and tried to click the bottom or other buttons it is not getting selected. It is taking only the area inside its parent window.
      How can i solve this issue ?

      Ansif

      1 Reply Last reply Reply Quote 0
      • T
        t3685 last edited by

        You need to take into account ListView::originX, ListView::originY, ListView::contentX and ListView::contentY.

        ListView (and Flickable) are only showing a part of the whole content. When you scroll the "move" their content to the right position. So you need to convert the coordinates you get from your MouseArea to the coordinates of the content in the ListView.

        1 Reply Last reply Reply Quote 0
        • X
          Xander84 last edited by

          there might be a better solution, I don't know exactly what you want to achieve but I guess you just want a click event for all items in the ListView?

          Why don't you use a MouseArea inside the delegate, so every item has its own MouseArea and no need to use itemAt with some "weird" calculations. :p

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            [quote author="t3685" date="1395916442"]You need to take into account ListView::originX, ListView::originY, ListView::contentX and ListView::contentY.

            ListView (and Flickable) are only showing a part of the whole content. When you scroll the "move" their content to the right position. So you need to convert the coordinates you get from your MouseArea to the coordinates of the content in the ListView.
            [/quote]

            Hi,
            Yes it works, thank you. I have used the contentY property and it is using the exact location.
            Thank you

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User last edited by

              [quote author="Xander84" date="1395927825"]there might be a better solution, I don't know exactly what you want to achieve but I guess you just want a click event for all items in the ListView?

              Wy don't you use a MouseArea inside the delegate, so every item has its own MouseArea and no need to use itemAt with some "weird" calculations. :p[/quote]

              I never used this behaviour. hence my problem is fixed

              1 Reply Last reply Reply Quote 0
              • T
                t3685 last edited by

                Don't forget to take into account originX and originY as well.

                1 Reply Last reply Reply Quote 0
                • X
                  Xander84 last edited by

                  [quote author="t3685" date="1395946982"]Don't forget to take into account originX and originY as well. [/quote]
                  There is no need for that if you use a MouseArea in the delegate or what do you mean!?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post