QML Text要素で、Webサイトへのハイパーリンクを作成し、それを1つなどのように表示したいのですが、クリックまたはタッチしても何も起こらず、リンクはデフォルトのブラウザーで開くはずです。
Text {
id: link_Text
text: '<html><style type="text/css"></style><a href="http://google.com">google</a></html>'
}
私が間違っていることについて何か考えはありますか?
わかりました。これを追加する必要があることがわかりました。
onLinkActivated: Qt.openUrlExternally(link)
文字列が正しくフォーマットされていれば、それ自体でリンクが開くと思ったので、私はもともとこのようなことを考えていませんでした。
ホバーのカーソルも変更したい場合は、次の組み合わせを行うことができます。
Text {
id: link_Text
text: '<html><style type="text/css"></style><a href="http://google.com">google</a></html>'
onLinkActivated: Qt.openUrlExternally(link)
MouseArea {
id: mouseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
}
}
ハイパーリンクを模倣するタスクに直面しました。ユーザーがハイパーリンクにカーソルを合わせると、テキストはハイパーリンクのようになります。ただし、ユーザーがリンクをクリックすると、URLを開く代わりにカスタマーハンドラーを呼び出す必要があります。多分これは誰かのために役立つでしょう。
Text{
id: hyperlinkButtonText
text: "Hyperlink button"
color: application.primaryColor
font.pixelSize: 12
font.bold:true
MouseArea{
id: mouseHyperlinkArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
// to do something on clicking the link
}
}
}
Rectangle{ /*Here is an underline item for the text above*/
visible: mouseHyperlinkArea.containsMouse
anchors.top:hyperlinkButtonText.bottom
anchors.topMargin: -1
width:hyperlinkButtonText.width
height: 0.5
color: application.primaryColor
}