QQuickItem::childAt(x, y) takes child transformations into account
authorShawn Rutledge <shawn.rutledge@digia.com>
Tue, 5 Feb 2013 17:11:34 +0000 (18:11 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 12 Feb 2013 17:46:52 +0000 (18:46 +0100)
Task-number: QTBUG-28706
Change-Id: Ib1738eac1319361398b1898db341d6e4be0fe5fd
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
src/quick/items/qquickitem.cpp

index e87f870..26af695 100644 (file)
@@ -3808,14 +3808,15 @@ void QQuickItem::forceActiveFocus()
 */
 QQuickItem *QQuickItem::childAt(qreal x, qreal y) const
 {
-    // XXX todo - should this include transform etc.?
     const QList<QQuickItem *> children = childItems();
     for (int i = children.count()-1; i >= 0; --i) {
         QQuickItem *child = children.at(i);
-        if (child->isVisible() && child->x() <= x
-                && child->x() + child->width() >= x
-                && child->y() <= y
-                && child->y() + child->height() >= y)
+        // Map coordinates to the child element's coordinate space
+        QPointF point = mapToItem(child, QPointF(x, y));
+        if (child->isVisible() && point.x() >= 0
+                && child->width() >= point.x()
+                && point.y() >= 0
+                && child->height() >= point.y())
             return child;
     }
     return 0;