【问题标题】:How to change the cursor's shape without using MouseArea?如何在不使用 MouseArea 的情况下更改光标的形状?
【发布时间】:2016-01-13 08:41:43
【问题描述】:
我查看了类似的主题,但没有太大帮助。
我在QML 中使用QtQuick.Controls.Button,当将鼠标悬停在按钮上时,我无法更改光标形状!我想在不使用MouseArea 的情况下实现这一目标。可以做什么?当我查看文档时,我找不到 cursorShape 属性或类似属性。
【问题讨论】:
标签:
qml
qt5
qtquick2
mouse-cursor
qtquickcontrols
【解决方案1】:
这是一种 hack,但您可以通过 __behavior 伪私有属性访问 Button 自己的 MouseArea。
Button {
text: qsTr("Hello World")
Component.onCompleted: __behavior.cursorShape = Qt.PointingHandCursor
}
或者,您可以非常轻松地创建自己的改进Button:
import QtQuick 2.3
import QtQuick.Controls 1.2
Button {
property alias cursorShape: mouseArea.cursorShape
MouseArea
{
id: mouseArea
anchors.fill: parent
onPressed: mouse.accepted = false
}
}
请注意,您可能必须在定义 Button 的位置显式导入 QML 模块,以掩盖 QtQuick.Controls 的 Button。