0

What is the parent of MouseArea, when it in the GroupBox? parent refers to some container:

GroupBox {
    width: 100; height: 100
    id: rec
    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onClicked: {
            console.log("\tparent" + parent + "\trec" + rec)
        }
    }
}

qml: parentQQuickItem_QML_15(0x3ad3590, "container") recGroupBox_QMLTYPE_12(0x3ad2790)

When the MouseArea in the Rectangle, Rectangle is its parent:

Rectangle {
    width: 100; height: 100
    id: rec
    color: "green"
    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onClicked: {
            console.log("\tparent" + parent + "\trec" + rec)
        }
    }
}

qml: parentQQuickRectangle(0x39d0cd0) recQQuickRectangle(0x39d0cd0)

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Ivan Kush
  • 2,958
  • 2
  • 23
  • 39

1 Answers1

2

It is common behaviour, in most QML controls (and windows), that an inner item takes up all the children of the control itself. It happens for Window, ScrollView, Flickable and even GroupBox. Such a component is available as a property (usually) called contentItem.

If you write an example which prints such a property you'll see that contentItem is the parent you are searching for:

import QtQuick 2.4
import QtQuick.Controls 1.3

ApplicationWindow {
    id: container

    width: 640
    height: 480
    visible: true

    property int clicksCounter: 0

    GroupBox {
        width: 100; height: 100
        id: rec
        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onClicked: {
                console.log("\tparent " + parent + "\tcontentItem " + rec.contentItem)
            }
        }
    }
}

Output:

qml: parent QQuickItem_QML_26(0x1411fc0, "container") contentItem QQuickItem_QML_26(0x1411fc0, "container")

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82