分组框中鼠标区域的父级



MouseAreaGroupBox中时,它的父级是什么?parent是指某些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_qmlype_12 (0x3ad2790)

MouseAreaRectangle, Rectangle是它的父:

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)

在大多数QML控件(和窗口)中,内部项占用控件本身的所有子项是常见的行为。WindowScrollViewFlickable甚至GroupBox都是如此。这样的组件可以作为一个名为contentItem的属性获得(通常)。

如果你写一个打印这样一个属性的例子,你会看到contentItem是你正在搜索的父节点:

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)
            }
        }
    }
}
输出:

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

相关内容

  • 没有找到相关文章

最新更新