View Full Version : QPlainTextEdit reload text
bunjee
25th April 2009, 11:34
Hey trolls,
I have a QPlainTextEdit.
I've load the content of a file.
Now in another editor I modify the content of that file.
Is it possible to get my QPlainTextEdit refreshed without getting my cursor / scrollbars screwed up ?
Thanks.
wagmare
25th April 2009, 11:59
check this thread in this forum
http://www.qtcentre.org/forum/f-qt-programming-2/t-problem-in-setting-cursor-position-in-readonly-qtextedit-19681.html/?highlight=QTextCursor
bunjee
25th April 2009, 14:24
Solved.
// Backup settings
int position = d->plainTextEdit->textCursor().position();
int vScrollPosition = d->plainTextEdit->verticalScrollBar()->value();
int hScrollPosition = d->plainTextEdit->horizontalScrollBar()->value();
// Getting content
QFile scriptFile(d->script->filePath());
scriptFile.open(QIODevice::ReadOnly);
d->plainTextEdit->setPlainText(scriptFile.readAll());
scriptFile.close();
// Restore settings
QTextCursor cursor = d->plainTextEdit->textCursor();
cursor.setPosition(position);
d->plainTextEdit->setTextCursor(cursor);
d->plainTextEdit->verticalScrollBar()->setValue(vScrollPosition);
d->plainTextEdit->horizontalScrollBar()->setValue(hScrollPosition);
Note: this resets the undo stack.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.