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

QML Item::contains() always returns true

    XMLWordPrintable

Details

    • 360fcf3a99d84b038326d05f8ea8718b40bff2c0

    Description

      Using the basic test below you can see that Item::contains( point ) always returns true:

      import QtQuick 2.3
      
      Rectangle {
          width: 400
          height: 400
          color: "green"
      
          Rectangle {
              id: block
              width: 50
              height: 50
              color: "red"
      
              anchors.centerIn: parent
          }
      
          MouseArea {
              anchors.fill: parent
      
              onClicked: {
                  var pnt = mapToItem( block, mouse.x, mouse.y );
                  console.log( "pnt x:", pnt.x, "y:", pnt.y );
                  if ( block.contains( pnt ) ) {
                      console.log( "Inside" );
                  } else {
                      console.log( "Outside" );
                  }
              }
          }
      }
      

      Inside is always printed regardless of the input coordinate. Adding debug to QQuickItem::contains(const QPointF &point) const reveals that the input arg is being converted to QPointF(0, 0) before it arrives.

      Attachments

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

        Activity

          People

            mitch_curtis Mitch Curtis
            cmannett85 Cam Mannett
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes