C++ (Qt)void QTextFormat::setObjectIndex ( int index )
C++ (Qt)void setFormat ( const QTextFormat & format )
C++ (Qt)QTextDocument *copyDocument = originalDocument->clone();QTextCursor cursor(copyDocument);QTextFrame *rootFrame = copyDocument->rootFrame();ProcessFrame(rootFrame, cursor, copyDocument);QString str = copyDocument->toHtml("UTF-8");delete copyDocument;
C++ (Qt)void ProcessFrame(QTextFrame *frame, QTextCursor &cursor, QTextDocument *doc){ QTextFrame::iterator it; for (it = frame->begin(); !(it.atEnd()); ++it) { QTextFrame *childFrame = it.currentFrame(); QTextBlock childBlock = it.currentBlock(); if (childFrame) { QTextTable *childTable = qobject_cast<QTextTable*>(childFrame); if (childTable) ProcessTable(childTable, cursor, doc); else ProcessFrame(childFrame, cursor, doc); } }}
C++ (Qt)QTextTable* table = cursor.insertTable();table->setProperty("MyTableId", int);.........QString strHtmlDoc = textEdit->toHtml();QDomDocument XmlDoc;QDomDocument NewXmlDoc;XmlDoc.setContent(strHtmlDoc); doFrame(textEdit->document()->rootFrame()); void doFrame(QTextFrame* frame) { QTextTable* table = qobject_cast<QTextTable*>(frame); if(table) { updateXml(table); } QList<QTextFrame*> FrameList = childFrames(); foreach (QTextFrame* f) { doFrame(f); }} void updateXml(QTextTable* table) { int MyTableId = table->property("MyTableId").toInt(); ... ...// Get next table from XmlDoc// Update QDomElement, setAttribute ( const QString & name, int value )// Add data to NewXmlDoc }