Results 1 to 4 of 4

Thread: How to make the text keep unchanged when changing the width of QTextEdit

  1. #1
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to make the text keep unchanged when changing the width of QTextEdit

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make the text keep unchanged when changing the width of QTextEdit

    What do you mean by "keep the first line of the block unchanged"? You mean you want it to be visible or...?

  3. #3
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to make the text keep unchanged when changing the width of QTextEdit

    Quote Originally Posted by wysota View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make the text keep unchanged when changing the width of QTextEdit

    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.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 06:57

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.