qt - SplitView 项目内的 MouseArea 将鼠标事件从 Splitview 句柄中移走

标签 qt qml qt5 qtquick2 qtquickcontrols2

我正在使用 qt quick controls 2 SplitView,似乎 SplitView 项内的任何 MouseArea 都将鼠标事件从SplitView 句柄。这意味着当 handle 位于具有 MouseArea 的组件上方时,无法拖动 handle ,例如Button,在 SplitView 的项目内。

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.13

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    SplitView {
        id: splitView
        anchors.fill: parent
        handle: Rectangle {
            id: handle
            implicitWidth: 20
            color: "red"
        }

        Page {
            id: firstPage
            Button {
                id: button
                implicitWidth: 100
                implicitHeight: 50
                text: "button"
            }
        }

        Page {
            id: secondPage
        }
    }
}

正常行为:

working gif

按钮阻止来自句柄的鼠标事件:

not working gif

我尝试将 splitViewhandle 的 z 值设置为大于 firstPagebutton 的 z 值但这没有用。

最佳答案

   Page {
        id: firstPage
        clip: true
        Button {
            id: button
            implicitWidth: 100
            implicitHeight: 50
            text: "button"
        }
    }

您必须在页面上激活剪辑。 我在一个空的 projet 上测试它工作。:D 我想 handle 栏下加载按钮的右侧仍然处于事件状态。 (如果有人确切知道为什么发表评论)

关于qt - SplitView 项目内的 MouseArea 将鼠标事件从 Splitview 句柄中移走,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64163192/

相关文章:

c++ - 使用 QGraphicsEffect 删除 QGraphicsItem 会导致段错误

c++ - 为什么我的应用程序在关闭时有时会因 SIGSEGV 而崩溃?

c++ - 在 QT GUI 中创建一个全局对象

qt - QML 对象 var 属性为 null QVariant(QJSValue, ) 来自 cpp

macos - 在 Qt 中组合工具栏和标题栏

c++ - 如何等待窗口在 Qt 中被隐藏?

c++ - Qt中是否需要一个一个查看才能知道一个组中选中了哪个radiobutton

c++ - Qt Quick的parent,和parent的id不一样

Qt qsTr() 处理复数

python - 使用 Python 从 QML 中动态创建的列表访问数据