我试图在光标下获得控制权。在我的例子中,我只能得到红色矩形,但我还需要得到其他的。
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
id: mainWindow
title: qsTr("Hello World")
width: 640
height: 480
Item {
id: parentPanel
anchors.fill: parent
MouseArea {
anchors.fill: parent
hoverEnabled: true
onMouseXChanged: moveMouse()
onMouseYChanged: moveMouse()
function moveMouse()
{
currentControl.text = parentPanel.childAt(mouseX, mouseY).color ? parentPanel.childAt(mouseX, mouseY).color : "not colored"
}
}
Rectangle {
id: redRect
anchors {
fill: parent
leftMargin: 50
bottomMargin: 50
}
color: "red"
Rectangle {
id: yellowRect
anchors {
fill: parent
leftMargin: 50
bottomMargin: 50
}
color: "yellow"
Rectangle {
id: greenRect
anchors {
fill: parent
leftMargin: 50
bottomMargin: 50
}
color: "green"
}
}
}
Text {
id: currentControl
anchors.left: parent.left
anchors.bottom: parent.bottom
}
}
}
我有正在运行程序的截图。绿色矩形内黄色,黄色内红色。当鼠标光标超过控件时,我需要获得控制参考。