QML之鼠标样式

http://blog.sina.com.cn/s/blog_a6fb6cc90102v204.html


 之前有介绍过Qt中设置鼠标样式的博文(c++版),可参考:Qt之鼠标样式

    QML中可以通过MouseArea的cursorShape属性来设置。
  • cursorShape : Qt::CursorShape
    此属性保存这个鼠标区域的光标形状。注意,在不显示鼠标光标的平台上可能没有任何效果。 

    为了只设置鼠标区域的光标形状,不接受鼠标事件则设置 acceptedButtons为none:
MouseArea { 
            cursorShape: Qt.IBeamCursor; 
            acceptedButtons: Qt.NoButton
         }

    以下为示例代码,可以进行测试比对:
import QtQuick 2.0

Rectangle {
    color: "white";
    width: 400;
    height: 400;

    Rectangle {
        color: "red";
        anchors.top: parent.top;
        anchors.left: parent.left;
        width: 300;
        height: 300;

        MouseArea {
            anchors.fill: parent;
            hoverEnabled: true;
            cursorShape: (containsMouse
                          ? (pressed
                             ? Qt.ClosedHandCursor
                             : Qt.OpenHandCursor)
                          : Qt.ArrowCursor);
        }
    }

    Rectangle {
        color: "green";
        anchors.bottom: parent.bottom;
        anchors.right: parent.right;
        width: 300;
        height: 300;

        MouseArea {
            anchors.fill: parent;
            hoverEnabled: true;
        }
    }
}

可用的光标形状:
  • 1、Qt.ArrowCursor
  • 2、Qt.UpArrowCursor
  • 3、Qt.CrossCursor
  • 4、Qt.WaitCursor
  • 5、Qt.IBeamCursor
  • 6、Qt.SizeVerCursor
  • 7、Qt.SizeHorCursor
  • 8、Qt.SizeBDiagCursor
  • 9、Qt.SizeFDiagCursor
  • 10、Qt.SizeAllCursor
  • 11、Qt.BlankCursor
  • 12、Qt.SplitVCursor
  • 13、Qt.SplitHCursor
  • 14、Qt.PointingHandCursor
  • 15、Qt.ForbiddenCursor
  • 16、Qt.WhatsThisCursor
  • 17、Qt.BusyCursor
  • 18、Qt.OpenHandCursor
  • 19、Qt.ClosedHandCursor
  • 20、Qt.DragCopyCursor
  • 21、Qt.DragMoveCursor
  • 22、Qt.DragLinkCursor

以下是Qt助手里面的内容:

QML之鼠标样式_第1张图片

你可能感兴趣的:(qml)