PDA

View Full Version : How to make the text keep unchanged when changing the width of QTextEdit



vvdounai
19th November 2007, 15:57
Hello, everyone!

I use QTextEdit to show a multiple line text and text is auto wrapped. However, when I read the file, e.g. to the middle part. then I change the width of the QtextEdit, then the vertical scroll bar range changes. then the content will also changes due to the auto wrap. Now I just want to keep the first line of the block what I am now reading unchanged, how can I do?

btw: I found the gEdit in GNOME have this feature:)

thanks!

wysota
19th November 2007, 18:58
What do you mean by "keep the first line of the block unchanged"? You mean you want it to be visible or...?

vvdounai
20th November 2007, 02:05
What do you mean by "keep the first line of the block unchanged"? You mean you want it to be visible or...?

suppose I have the following lines in the text:

aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccccc
ddddddddddd
...................
zzzzzzzzzzzzz

Then I start to read the text from aaaa....

when the textedit shows the first line as ccccccccc..cc, then when I change the width of the textedit, the cc.. line may disappear because of the autowrap. I want to keep the line still visiable in the screen.

wysota
20th November 2007, 08:03
If the text edit is not read only, then the simplest possible way to achieve this is to call QTextEdit::ensureCursorVisible(). You might call it in a reimplementation of resizeEvent for the widget or an event filter.