Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-34712

mapTo/FromItem() and contains() are non-intuitive to use together

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Cannot Reproduce
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • None

      These functions somewhat naturally fit together (a reasonable use case in a MouseArea might be to map the mouse location to another item, and then see if that item contains the mouse), but are not intuitive to use together. The following example demonstrates:

      import QtQuick 2.0
      
      Item {
          width: 400; height: 400
      
          Rectangle {
              id: greenRect
              color: "green"
              width: 50; height: 50
              anchors.centerIn: parent
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  var pos = mapToItem(greenRect, mouse.x, mouse.y)
                  console.log("pos", greenRect.contains(pos)) // always true, no matter where you click (no error generated)
                  console.log("myPoint", greenRect.contains(Qt.point(pos.x, pos.y))) // true only when clicking within the green rectangle
              }
          }
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mbrasser Michael Brasser
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes