首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用MouseArea覆盖行?

如何用MouseArea覆盖行?
EN

Stack Overflow用户
提问于 2017-11-25 07:45:18
回答 0查看 568关注 0票数 2

在我的示例中,为什么MouseArea没有涵盖整个item_row组件?如果是这样,那么将鼠标放在Pane上时,它将变为红色。我希望MouseArea覆盖整个Row,所以当我将鼠标放在蓝色方块或标签上时,整个窗格会变成红色,但现在它只在空白区域起作用。我怎么发动汽车呢?

这是代码,与qmlscene一起运行

代码语言:javascript
复制
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)
                }
            }
        }
    }
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47481312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档