Results 1 to 5 of 5

Thread: QtextEdit Enable Disable Auto Scroll

  1. #1
    Join Date
    Sep 2013
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtextEdit Enable Disable Auto Scroll

    Hello,

    I've got a debug window with a QTextEdit to display some informations, and I would like to be able to enable / disable the auto scrolling.

    I tried to use QtextCursor but it doen't work.. I had a look on the documentation and I don't find how to do this.. :

    here it is what I tried and doesn't work:

    Qt Code:
    1. void myClass::on_pushButton_PauseTextEdit_clicked()
    2. {
    3. if(ui->pushButton_PauseTextEdit->text().contains("Pause"))
    4. {
    5. //I want the QTextEdit Stop scrolling
    6.  
    7. ui->pushButton_PauseTextEdit->setText("Go");
    8.  
    9. cursorTextEditLog.setPosition(QTextCursor::NoMove, QTextCursor::MoveAnchor);
    10. ui->textEditLog->setTextCursor(cursorTextEditLog);
    11.  
    12. }
    13. else
    14. {
    15. //I want to go down to the last information which has been append on QTextEdit and scroll
    16.  
    17. ui->pushButton_PauseTextEdit->setText("Pause");
    18.  
    19. cursorTextEditLog.setPosition(QTextCursor::end, QTextCursor::MoveAnchor);
    20. ui->textEditLog->setTextCursor(cursorTextEditLog);
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    If someone has a clue...
    Thanks.


    Added after 19 minutes:


    for the return to "the last information which has been append on QTextEdit and scroll" it works doing this:
    Qt Code:
    1. ui->pushButton_PauseTextEdit->setText("Pause");
    2.  
    3. cursorTextEditLog.movePosition(QTextCursor::end, QTextCursor::MoveAnchor,1);
    4. ui->textEditLog->setTextCursor(cursorTextEditLog);
    To copy to clipboard, switch view to plain text mode 
    Last edited by zodd; 1st July 2019 at 15:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,366
    Thanks
    36
    Thanked 1,536 Times in 1,487 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QtextEdit Enable Disable Auto Scroll

    Just as a suggestion: do not keep "state" in the button's text or icon.

    Your check for "Pause" will break if you change the text and/or have translations.

    Either have a stateful button (setCheckable(true)) or keep the state in a boolean member that is toggled by the slot.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtextEdit Enable Disable Auto Scroll

    Thank you for your advise. I did this for a quick test.

    I manage to return to "the last information which has been append on QTextEdit and auto scroll. But I still don't manage to stop the scrolling when I click on pause button, but it works when I click directly in the QTextEdit.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,366
    Thanks
    36
    Thanked 1,536 Times in 1,487 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QtextEdit Enable Disable Auto Scroll

    You could try

    * get the scroll bar position
    * add the text
    * reset the scrollbar position

    Cheers,
    _

  5. #5
    Join Date
    Sep 2013
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtextEdit Enable Disable Auto Scroll

    Thanks, I'll try this.

    Cheers.

Similar Threads

  1. How to disable & enable a row in QTreeView
    By chithara in forum Newbie
    Replies: 6
    Last Post: 24th May 2019, 05:21
  2. Enable and Disable Close (X)
    By anh5kor in forum Newbie
    Replies: 2
    Last Post: 25th March 2015, 06:45
  3. Replies: 3
    Last Post: 6th October 2011, 11:14
  4. QTextEdit + auto scroll
    By jbpvr in forum Qt Programming
    Replies: 7
    Last Post: 25th March 2008, 09:30
  5. disable/enable shortcut
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 10:58

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.