31

QML Text要素で、Webサイトへのハイパーリンクを作成し、それを1つなどのように表示したいのですが、クリックまたはタッチしても何も起こらず、リンクはデフォルトのブラウザーで開くはずです。

Text {
    id: link_Text
    text: '<html><style type="text/css"></style><a href="http://google.com">google</a></html>'
}

私が間違っていることについて何か考えはありますか?

4

3 に答える 3

58

わかりました。これを追加する必要があることがわかりました。

onLinkActivated: Qt.openUrlExternally(link)

文字列が正しくフォーマットされていれば、それ自体でリンクが開くと思ったので、私はもともとこのようなことを考えていませんでした。

于 2012-09-21T18:57:22.663 に答える
0

ホバーのカーソルも変更したい場合は、次の組み合わせを行うことができます。

    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
        }
    }
于 2021-10-19T23:07:23.917 に答える
0

ハイパーリンクを模倣するタスクに直面しました。ユーザーがハイパーリンクにカーソルを合わせると、テキストはハイパーリンクのようになります。ただし、ユーザーがリンクをクリックすると、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
} 
于 2021-10-22T10:32:16.443 に答える