如何在QML的RichText中使用html源将图片居中?

LxL*_*LxL 5 c++ qt qml

我想使用RichText. 我试过<center>标签和text-align属性。它们都不起作用。

import QtQuick 2.0
import QtQml.Models 2.1
import QtQuick.Window 2.2
import QtQuick.Controls 1.2


ApplicationWindow{
    width: Screen.width; height: Screen.height; color: "#d5d6d8"
    visible:true
    Rectangle {
        color: "#33cc94"
        width: parent.width; height: parent.height
        id : main

        Flickable {
            id:textArea
            anchors.fill: parent
            contentHeight: textBrowser.height
            contentWidth: textBrowser.width
            enabled: false
            Text {
                id:textBrowser
                textFormat: Text.RichText
               // visible:false
             //   text: "<center><img src=\"Icons/TroopCards/ArchersCard.png\"  /></center>";
                text: "<p style=\"text-align:center\">
                          <img  src=\"Icons/TroopCards/ArchersCard.png\" />
                       </p>
                       <p style=\"text-align:center\">Some text at middle</p>";
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

结果:

左对齐的图像!

如何在 QML 中使用 html 将图像居中?!

syn*_*ker 0

尝试这个:

Text {
            id:textBrowser
            anchors.horizontalCenter: parent.hrizontalcenter
            textFormat: Text.RichText
            text: "<p style=\"text-align:center\">
                      <img  src=\"Icons/TroopCards/ArchersCard.png\" />
                   </p>
                   <p style=\"text-align:center\">Some text at middle</p>";
        }
Run Code Online (Sandbox Code Playgroud)