使用QML制作超链接并打开超链接

来源:互联网 发布:淘宝的宝贝卖点填什么 编辑:程序博客网 时间:2024/05/21 21:39

使用QML中的Text来实现超链接并打开


代码如下:

import QtQuick 2.3import QtQuick.Window 2.2Window {    visible: true    MouseArea {        anchors.fill: parent        onClicked: {            Qt.quit();        }    }    MouseArea{        anchors.centerIn: parent        width: hp.width        height: hp.height        hoverEnabled: true        cursorShape: containsMouse ? (pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor) : Qt.ArrowCursor        Text {            id: hp            text: "<a href='http://www.baidu.com'><h1>点击进入首页</h1></a>"            anchors.centerIn: parent            onLinkActivated: Qt.openUrlExternally(link)        }    }}

只要为text属性复制上HTML中的<a>元素就可变成超链接,使用Qt.openUrlExternally来打开它

利用MouseArea来实现鼠标放上超链接时候的样式。


看看效果图:



点击之后就会使用默认浏览器打开http://www.baidu.com


是不是很简单? over.



0 0
原创粉丝点击