[Qt-interest] How to scroll QTextEdit to the end
Andre Somers
andre at familiesomers.nl
Mon Jun 21 08:14:41 CEST 2010
Op 21-6-2010 0:53, Nikos Chantziaras schreef:
> On 06/21/2010 01:21 AM, yogesh upreti wrote:
>
>> Hallo Group,
>> I have a QTextEdit Widget in my gui, which I use to display the log of
>> work being performed by my programme.
>> How do I make it sure that in this text edit (which is read only),
>> whenever I insert a text, it should scroll to the bottom.
>> I use this code in textChanged() signal of MyTextEdit. But this somehow
>> doesn't work.
>>
>> QScrollBar *hbar = ui->MyTextEdit->horizontalScrollBar();
>> hbar->setValue(hbar->maximum());
>>
>> Is this piece of code correct???
>>
> Try QAbstractSlider::triggerAction(QAbstractSlider::SliderToMaximum).
>
Perhaps you should only do this if the slider was not moved manually in
the meantime, and the cursor position is at the end (or something like
that). Otherwise, users won't be able to scroll comfortably and take a
little bit of time to read the log messages. It is *very* annoying if
you try to read a log, and it keeps scrolling away to the end because a
new message has been added...
André
More information about the Qt-interest-old
mailing list