Html 带img标记和换行模式的Qml文本
当我设置wrapMode,然后在文本组件中使用html标记时,我发现了非常奇怪的行为。您可以尝试以下示例:Html 带img标记和换行模式的Qml文本,html,qt,qml,Html,Qt,Qml,当我设置wrapMode,然后在文本组件中使用html标记时,我发现了非常奇怪的行为。您可以尝试以下示例: Text { id: text height: 32 width: 100 text: "<img width=\"32\" height=\"32\" align=\"middle\" src=\"http://vk.com/images/emoji/D83DDE0E.png\">" wrapMode: Text.WordWrap }
Text {
id: text
height: 32
width: 100
text: "<img width=\"32\" height=\"32\" align=\"middle\" src=\"http://vk.com/images/emoji/D83DDE0E.png\">"
wrapMode: Text.WordWrap
}
Button {
anchors.top: text.bottom
text: "push"
onClicked: {
text.text = text.text + "<img width=\"32\" height=\"32\" align=\"middle\" src=\"http://vk.com/images/emoji/D83DDE0E.png\">"
}
}
文本{
id:文本
身高:32
宽度:100
案文:“”
wrapMode:Text.WordWrap
}
钮扣{
anchors.top:text.bottom
文本:“推送”
再次点击:{
text.text=text.text+“”
}
}
若你们用这个代码启动应用程序,并等待图像从网络加载,点击“推”按钮2次,你们会看到所有的图像消失!然而,若删除“wrapMode:Text.WordWrap”,当图像的大小变大到该宽度时,图像将不会消失
那我该怎么修呢?我需要设置宽度和自动换行模式,但是我还需要在文本组件中使用html标记能否尝试保持文本的宽度以适合其内容
Text {
id: text
height: 32
// fit width to contentWidth
width: contentWidth
text: "<img width=\"32\" height=\"32\" align=\"middle\" src=\"http://vk.com/images/emoji/D83DDE0E.png\">"
// Text.WordWrap is not needed.
//wrapMode: Text.WordWrap
}
文本{
id:文本
身高:32
//将宽度调整为内容宽度
宽度:contentWidth
案文:“”
//不需要Text.WordWrap。
//wrapMode:Text.WordWrap
}