首页 > 代码库 > Qt入门 - QTextEdit

Qt入门 - QTextEdit

QTextEdit *textedit = new QTextEdit();

 

获取文本框内容:QString qstring = textedit->toPlainText();

设置文本框内容:textedit->setPlainText(qstring);

 

自动跳到最后一行:

QTextCursor tc = textEdit->textCursor();
tc.movePosition(QTextCursor::End);
textEdit->setTextCursor(tc);

自动跳到某一行:

QTextCursor tc = textCursor();
int position = document()->findBlockByNumber ( line-1 ).position();
tc.setPosition(position,QTextCursor::MoveAnchor);
setTextCursor( tc );

 

设置最大行数:textEdit->document()->setMaximumBlockCount(linecnt);

获取行数:textEdit->document()->lineCount();