PDA

View Full Version : QtextEdit Enable Disable Auto Scroll



zodd
1st July 2019, 16:39
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:



void myClass::on_pushButton_PauseTextEdit_clicked()
{
if(ui->pushButton_PauseTextEdit->text().contains("Pause"))
{
//I want the QTextEdit Stop scrolling

ui->pushButton_PauseTextEdit->setText("Go");

cursorTextEditLog.setPosition(QTextCursor::NoMove, QTextCursor::MoveAnchor);
ui->textEditLog->setTextCursor(cursorTextEditLog);

}
else
{
//I want to go down to the last information which has been append on QTextEdit and scroll

ui->pushButton_PauseTextEdit->setText("Pause");

cursorTextEditLog.setPosition(QTextCursor::end, QTextCursor::MoveAnchor);
ui->textEditLog->setTextCursor(cursorTextEditLog);
}
}



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:


ui->pushButton_PauseTextEdit->setText("Pause");

cursorTextEditLog.movePosition(QTextCursor::end, QTextCursor::MoveAnchor,1);
ui->textEditLog->setTextCursor(cursorTextEditLog);

anda_skoa
1st July 2019, 18:50
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,
_

zodd
2nd July 2019, 10:00
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.

anda_skoa
3rd July 2019, 10:24
You could try

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

Cheers,
_

zodd
8th July 2019, 16:01
Thanks, I'll try this.

Cheers.