From e105229e4443fbb05496fcec02a83cb8ffba09db Mon Sep 17 00:00:00 2001 From: Sebastian Goth Date: Tue, 17 Jun 2014 19:26:50 +0200 Subject: [PATCH] Keep scrolled down views through resizeEvents There's a reason for everything... ChatView is rendered into the viewport from top to bottom. If we don't scroll to bottom, the topmost line doesn't change and therefore the scrollbar will move upwards on shrinking events. So if the scrollbar was at bottom before the resize, make it stay there. --- src/qtui/chatview.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index b40b2900..b8cb2f17 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -126,11 +126,26 @@ bool ChatView::event(QEvent *event) void ChatView::resizeEvent(QResizeEvent *event) { + // if view is currently scrolled to bottom, we want it that way after resizing + bool atBottom = (_lastScrollbarPos == verticalScrollBar()->maximum()); + QGraphicsView::resizeEvent(event); + // if scrolling to bottom, do it immediately. + if(atBottom) + { + // we can reduce viewport updates if we scroll to the bottom allready at the beginning + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + } + scene()->updateForViewport(viewport()->width(), viewport()->height()); adjustSceneRect(); + if(atBottom) + { + _lastScrollbarPos = verticalScrollBar()->maximum(); + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + } checkChatLineCaches(); } -- 2.20.1