Question

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.

Was it helpful?

Solution

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

QTextEdit::clear()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top