From f8d835cd22de89bc130ff0413228cfea0ebfd8ac Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Thu, 26 Dec 2013 22:40:26 +0100 Subject: [PATCH] Fix scrolling --- CategorizedView.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CategorizedView.cpp b/CategorizedView.cpp index 1860f095..6164cde6 100644 --- a/CategorizedView.cpp +++ b/CategorizedView.cpp @@ -9,6 +9,7 @@ #include #include #include +#include template bool listsIntersect(const QList &l1, const QList t2) @@ -182,6 +183,22 @@ void CategorizedView::updateGeometries() qDeleteAll(m_categories); m_categories = cats.values(); + if (m_categories.isEmpty()) + { + verticalScrollBar()->setRange(0, 0); + } + else + { + int totalHeight = 0; + foreach (const Category *category, m_categories) + { + totalHeight += category->totalHeight() + m_categoryMargin; + } + // remove the last margin (we don't want it) + totalHeight -= m_categoryMargin; + verticalScrollBar()->setRange(0, totalHeight- height()); + } + update(); } @@ -513,6 +530,8 @@ void CategorizedView::mouseDoubleClickEvent(QMouseEvent *event) void CategorizedView::paintEvent(QPaintEvent *event) { QPainter painter(this->viewport()); + QPoint offset(horizontalOffset(), verticalOffset()); + painter.translate(-offset); int y = 0; for (int i = 0; i < m_categories.size(); ++i)