How can I auto scroll for the scroll area? For example, when there is a new update instead of the view of the scroll area staying the same, I want to go down with the new text. Think of it as in a CMD console, when you type a command it autoscroll with the output.
Use QTextEdit.moveCursor
to set the location you want to scroll to, and then use QTextEdit.ensureCursorVisible
to scroll to it:
textedit.moveCursor(QtGui.QTextCursor.End)
textedit.ensureCursorVisible()
QTextEdit
- after all, a QScrollArea
isn't much use on its own. –
Rectifier I was just going to respond to the other answer, but I just didn't know the best way to phrase it in the space allotted.
QScrollArea's are very useful widgets to use when designing custom PyQt widgets - I use them often. Things like rollout widgets, card widgets, anything where you could be displaying multiple sub-widgets with the need for scrolling can be a very useful utility. I don't agree with the idea that a QScrollArea isn't much use on its own.
The QTextEdit answer solves the problem the developer was facing - but only because it so happens the question is really about that. If you're trying to scroll a text edit, go with that answer.
However, if you are searching for an answer to the actual question and come across this thread, then the way to scroll down a QScrollArea is by actually modifying the scrollbar's value.
area = QScrollArea(parent)
vbar = area.verticalScrollBar()
vbar.setValue(vbar.maximum())
If you want to scroll to particular areas or anything (like implementing the ensureCursorVisible) then you want to take the location on the area's widget that you want to scroll to, figure out the percentage of the height of it, and apply that value to the vertical scrollbar. (Pseudocode)
QScrollBar
already has the functions ensureVisible
and ensureWidgetVisible
that will scroll both vertically and horizontally to either a specific point or child widget, so there's no need to reimplement them. –
Rectifier Use QTextEdit.moveCursor
to set the location you want to scroll to, and then use QTextEdit.ensureCursorVisible
to scroll to it:
textedit.moveCursor(QtGui.QTextCursor.End)
textedit.ensureCursorVisible()
QTextEdit
- after all, a QScrollArea
isn't much use on its own. –
Rectifier © 2022 - 2024 — McMap. All rights reserved.