演示效果

1.鼠标区域相关属性
- hoverEnabled: true;//鼠标在控件范围内
- cursorShape: (containsMouse? Qt.PointingHandCursor: Qt.ArrowCursor);//显示手式鼠标
2.鼠标点击处理
onClicked: Qt.openUrlExternally("https://blog.csdn.net/fittec") //打开URL
完整qml源码
- import QtQuick 2.12
- import QtQuick.Controls 2.12
- import QtQuick.Layouts 1.12
-
- ApplicationWindow {
- visible: true
- width: 400
- height: 400
- title: qsTr("Qt基于Qml超链接使用")
-
- Rectangle {
- width: 100
- height: 50
- anchors.centerIn: parent
- color: "lightblue"
- radius: 10
- Text {
- anchors.centerIn: parent
- text: '打开CSDN'
- MouseArea {
- anchors.fill: parent;
- hoverEnabled: true;//鼠标在控件范围内
- cursorShape: (containsMouse? Qt.PointingHandCursor: Qt.ArrowCursor);//显示手式鼠标
- onClicked: Qt.openUrlExternally("https://blog.csdn.net/fittec") //打开URL
- }
- }
-
- }
- }