QTextCursor cursor = textEdit->textCursor();cursor.movePosition(QTextCursor::Start); QTextBlockFormat bf;QTextCharFormat cf; cursor.insertBlock(bf, cf);cursor.insertText(text);
#include <QtGui>int main(int argc, char **argv){ QApplication a(argc, argv); QTextEdit d; QTextDocument td; QTextCursor tc(&td); tc.insertText("This is a test"); d.setDocument(&td); d.show(); return a.exec();}
tc.insertText("This is a test", cf);
QApplication a(argc, argv);> QTextEdit d;> QTextDocument td;> QTextCursor tc(td.begin());> QTextBlockFormat bf;> QTextCharFormat cf;> cf.setAnchor(true);> cf.setAnchorName(QString::number(0));> tc.insertBlock(bf, cf);> tc.insertText("This is a test");> QTextCursor appendCursor(td.end());> appendCursor.insertBlock();> appendCursor.insertText("test");> d.setDocument(&td);> d.show();> return a.exec();
appendCursor.movePosition(QTextCursor::End);