I have a QTextBrowser
that displays lines of QString
and an Int
. The messages looks something like this:
Message a counter 1
Message a counter 2
Message a counter 3
Message b counter 1
Instead of always appending a new line for each incrementation of the counter I want to just increment the Int
in the last message (the last line). What is the most efficient way to do this?
I came up with this code to remove only the last line in the QTextBrowser
:
ui->outputText->append(messageA + QString::number(counter));
ui->outputText->moveCursor( QTextCursor::End, QTextCursor::MoveAnchor );
ui->outputText->moveCursor( QTextCursor::StartOfLine, QTextCursor::MoveAnchor );
ui->outputText->moveCursor( QTextCursor::End, QTextCursor::KeepAnchor );
ui->outputText->textCursor().removeSelectedText();
ui->outputText->append(messageA + QString::number(++counter));
Unfortunately this leaves me with an empty line after removing the last line which looks very ugly. What is the best way to achieve this that doesn't involve clearing the whole QTextBroswer
and appending each line again.