在我的示例中,为什么MouseArea没有涵盖整个item_row组件?如果是这样,那么将鼠标放在Pane上时,它将变为红色。我希望MouseArea覆盖整个Row,所以当我将鼠标放在蓝色方块或标签上时,整个窗格会变成红色,但现在它只在空白区域起作用。我怎么发动汽车呢?
这是代码,与qmlscene一起运行
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 680
title: qsTr("Hello World")
StackView {
anchors.fill: parent
Pane {
id: item_pane
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
contentHeight: parent.height
Row {
id: item_row
Rectangle {
color: "blue"
antialiasing: true
width: 150
height: 150
}
Pane {
background: Rectangle {
color: "transparent"
}
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
ColumnLayout {
Label {
text: "Some data"
Layout.alignment: Qt.AlignHCenter
font.bold: true
}
Grid {
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
columns: 2
rows: 3
Label {
text: "Field1:"
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
}
Label {
text: "1 sec"
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
}
Label {
text: "Field 2"
}
Label {
text: "30 kg"
}
Label {
text: "Field 3"
}
Label {
text: "30 years"
}
}
}
}
MouseArea {
id: mouse_area
hoverEnabled: true
//anchors.fill: parent
onEntered: {
item_pane.background.color="red"
}
onExited: {
item_pane.background.color="#ffffff"
}
}
Component.onCompleted: {
mouse_area.x=item_row.x
mouse_area.y=item_row.y
mouse_area.width=item_row.width
mouse_area.height=item_row.height
console.log("x="+item_row.x+",y="+item_row.y+"width=" + item_row.width +",height="+item_row.height)
}
}
}
}
}https://stackoverflow.com/questions/47481312
复制相似问题