Results 1 to 3 of 3

Thread: Disable auto-scrolling in QPlainTextEdit

  1. #1
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Disable auto-scrolling in QPlainTextEdit

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Disable auto-scrolling in QPlainTextEdit

    you can set the scroll policy via setVerticalScrollBarPolicy().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable auto-scrolling in QPlainTextEdit

    Quote Originally Posted by high_flyer View Post
    you can set the scroll policy via setVerticalScrollBarPolicy().
    Thanks, but this not work:
    Qt Code:
    1. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    2. appendHtml(html);
    3. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    To copy to clipboard, switch view to plain text mode 
    This code doesn't disable scrolling of text. Moreover, scrolling to bottom always.

    I found(probably good for me) solution for disable scrolling:
    Qt Code:
    1. ...
    2. volatile bool lock = false;
    3. ...
    To copy to clipboard, switch view to plain text mode 
    override virtual function scrollContentsBy of QPlainTextEdit:
    Qt Code:
    1. void my_plaintextedit::scrollContentsBy(int dx, int dy)
    2. {
    3. if(lock == false)
    4. QPlainTextEdit::scrollContentsBy(dx, dy);
    5. }
    To copy to clipboard, switch view to plain text mode 
    and:
    Qt Code:
    1. void my_plaintextedit::append_line(const QString & html)
    2. {
    3. if(mouse_press) //is mouse button pressed in viewport of QPlainTextEdit?
    4. lock = true;
    5. appendHtml(html);
    6. lock = false;
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QPlainTextEdit auto scroll
    By faldzip in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2010, 18:11
  2. auto scrolling QTextEdit
    By msmihai in forum Newbie
    Replies: 1
    Last Post: 8th January 2009, 19:08
  3. QPlainTextEdit scrolling
    By roxton in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2008, 16:55
  4. How did I disable auto-scrolling function in tree-view
    By alfa_wu in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2007, 08:31
  5. How to disable auto-repeat?
    By lumber44 in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 09:20

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
  •  
Qt is a trademark of The Qt Company.