QtQuick中解析富文本<初>


#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..
        }
    }

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值