如何获取在富文本中单击的图像?

时间:2017-02-16 09:37:09

标签: html qt qml frontend

有一个用QML编写的实时通讯工具,邮件以 html 格式传输。

simple code:

Rectangle{
    width:300
    height: 300

    Rectangle{ // simple bubble

        anchors.centerIn: parent
        width: parent.width-100
        height: parent.height-100
        color:"#f0f0f0"
        radius: 10

        TextEdit {  //simple message show

            anchors.fill: parent
            readOnly: true
            selectByMouse: true
            clip: true
            text: "<!DOCTYPE html>
                    <html>
                    <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head>
                        <body style=\"font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;\">
                            this is an image:
                            <img alt=\"\" src=\"file:/local/image.png\" />
                        </body>
                    </html>
                "
            textFormat: Text.RichText
        }
    }
}

我的问题是如何从 BubbleChatWidget 中获取点击的图片?

像: click action

类似的问题:here

当我参考电报(网络)时,我发现电报信息不会同时包含文字和图片。 link

1 个答案:

答案 0 :(得分:1)

您先预先解析文本,然后将每个图片打包在链接<a ...>...</a>中。

这样您就可以使用linkActivated(link) - 信号来注册点击。

参见文档:

相关问题