您的位置:首页 > 产品设计 > UI/UE

QtQuick中解析富文本<初>

2016-07-05 22:26 645 查看
#include<QTextFragment>
void  TQmlHelper::makeDoc(  QQuickTextDocument*   doc)
{

jAVA_QMessage("开始");
QTextDocument *document =doc->textDocument();
if(document==NULL)
{
jAVA_QMessage("NULL  DOCUMENT");
}
QTextBlock  currentBlock = document->begin();
QTextBlock::iterator it;

while( true)
{
for (it = currentBlock.begin(); !(it.atEnd()); )
{
QTextFragment currentFragment = it.fragment();
QTextImageFormat newImageFormat = currentFragment.charFormat().toImageFormat();

if (newImageFormat.isValid()) {
// 为image
jAVA_QMessage(newImageFormat.name());
}
++it;

}

currentBlock = currentBlock.next();
jAVA_QMessage("一循环");
if(!currentBlock.isValid())
{

break;
}

}
}


Rectangle{

id:sendroot
xxx..

property var offsetBeginX: 20
property var offsetendx: 10
Rectangle{
id: flickable
x:offsetBeginX
anchors.bottom: parent.bottom
width: sendroot.width - btn.width -offsetBeginX-offsetendx
height:edit.focus==true?flick.height:btn.height
color: "transparent"
radius: 5
border.width: 1
border.color: "#cccccc"
clip: true
Flickable{
id:flick
width: parent.width
height: contentHeight>100?100:contentHeight

contentHeight: edit.height
TextArea.flickable:   TextArea{
Material.foreground : "#ffffff"
id:edit
padding: 0
width: parent.width
font.pointSize: 14
height: contentHeight>btn.height?contentHeight:btn.height
wrapMode: TextArea.Wrap
textFormat: TextEdit.RichText
text:"Hello~~"
Component.onCompleted: {
edit.insert(edit.length,"<img width='48' height='48' src='qrc:/image/close_1.png'>");

}

onTextChanged: {
lizi.dodo(20)
}

onFocusChanged: {
if(focus == true)
{
cursorPosition = length

}
}

Lizi{
id:lizi
x:edit.cursorRectangle.x
y:edit.cursorRectangle.y
每秒发射个数:10
初始大小:8
大小变化范围:14
初始生命:1000
生命变化范围:500
粒子速度:20
角度:0
角度变化范围:360
}
}

ScrollBar.vertical: ScrollBar{
active: true
pressed: true}
}

}

Ola.Button{

x:flickable.x+flickable.width + offsetendx
anchors.bottom: parent.bottom
id:btn
text:"发送"
isDefault: true
//        font.bold: true
//        font.pointSize: 14

height: 40
width:  100
onClicked: {
myapp.jAVA_QMessage(edit.textDocument);
myapp.makeDoc(edit.textDocument);
xxx..
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: