문제

I'm new to QT, young at programming, and not understanding all the help materials for the classes in QT.

I have the following code, which executes on a button click, inserting text. This works fine but I want to clear the textEdit first, then insert the new text. Can anyone point me in the right direction here? Any help is much appreciated.

QTextCharFormat textFormat;
QTextCursor cursor(ui->textEdit->textCursor());
cursor.insertText("<some text to insert", textFormat);

It appears that I have to use setPosition() and movePosition() to select the text, then removeSelectedText() to clear it. I don't know how to determine the first and last positions in the document.

도움이 되었습니까?

해결책

QTextEdit has a clear function, which deletes all text. In the documentation it's listed as a Slot.

QTextEdit::clear()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top