Results 1 to 3 of 3

Thread: Moving cursor in QPlainTextEdit

  1. #1

    Default Moving cursor in QPlainTextEdit

    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


    Qt Code:
    1. void RelosMainWindow::have_shellinput()
    2. {
    3. ui->shell_output->setPlainText(ui->shell_input->text() + "\n");
    4. ui->shell_output->moveCursor(QTextCursor::EndOfLine);
    5. ui->shell_input->clear();
    6. qDebug() << ui->shell_output->overwriteMode();
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving cursor in QPlainTextEdit

    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()

  3. #3

    Default Re: Moving cursor in QPlainTextEdit

    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.

Similar Threads

  1. why pushbutton moving??
    By Shuchi Agrawal in forum Qt Tools
    Replies: 7
    Last Post: 19th January 2007, 17:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.