PDA

View Full Version : Moving cursor in QPlainTextEdit



pgbackup
11th September 2009, 18:50
Hi,

I am trying to create an interface where the user types a "shell command" on a QLineEdit. I process this command and dump the output to a "shell output" which is a QPlainTextEdit. I have the basic code shown below. But this keeps overwriting the first line on QPlainTextEdit. I want to keep appending to the buffer (so as to a get some sort of a "log"). Rather than appending to a QString, I tried advancing the cursor to the end of line, but that doesn't seem to work. It keeps overwriting on the same line. Can someone tell me what I'm doing wrong?

Thanks



void RelosMainWindow::have_shellinput()
{
ui->shell_output->setPlainText(ui->shell_input->text() + "\n");
ui->shell_output->moveCursor(QTextCursor::EndOfLine);
ui->shell_input->clear();
qDebug() << ui->shell_output->overwriteMode();
}

profoX
11th September 2009, 18:54
If I understand your question correctly, you want to append text to the shell_output QPlainTextEdit instead of overwrite the text? Then use QPlainTextEdit::appendPlainText() instead of setPlainText()

pgbackup
11th September 2009, 19:26
Thanks a lot. Yes, I just want to keep adding to the shell_output. I don't know why I glanced over this function in the Qt 4.5 docs. This should be exactly what I need.