PDA

View Full Version : Disable auto-scrolling in QPlainTextEdit



lukass
19th February 2011, 14:03
Hello.
I want append html to the end of document without scroll to the bottom in QPlainTextEdit.

One way I was saving and restoring scrollbar position, but this generate flicker of scrollbar.
How can I disable auto scrolling to the end of document in appendHtml(), when vertical slider is on maximum position?

high_flyer
21st February 2011, 09:40
you can set the scroll policy via setVerticalScrollBarPolicy().

lukass
21st February 2011, 10:31
you can set the scroll policy via setVerticalScrollBarPolicy().

Thanks, but this not work:

setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
appendHtml(html);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
This code doesn't disable scrolling of text. Moreover, scrolling to bottom always.

I found(probably good for me) solution for disable scrolling:

...
volatile bool lock = false;
...
override virtual function scrollContentsBy of QPlainTextEdit:

void my_plaintextedit::scrollContentsBy(int dx, int dy)
{
if(lock == false)
QPlainTextEdit::scrollContentsBy(dx, dy);
}
and:

void my_plaintextedit::append_line(const QString & html)
{
if(mouse_press) //is mouse button pressed in viewport of QPlainTextEdit?
lock = true;
appendHtml(html);
lock = false;
}