Details
-
Bug
-
Resolution: Duplicate
-
P3: Somewhat important
-
4.5.0
-
None
Description
If one of the two QScrollBar of a QGraphicsView is always visible (Qt::ScrollBarAlwaysOn), the width of the scrollbar is not correct. This bug let you can scroll outside the sceneRect and the scrollbar "jump" when sceneRect do not fit in the view.
Here is an example to reproduce the problem (resize horizontally, you will see the scrollbar jump):
#include <QtGui>
int main(int argc, char** argv)
{
QApplication qapp(argc, argv);
QGraphicsScene s;
QGraphicsRectItem ri(0, 0, 500, 500);
ri.setBrush(Qt::black);
s.addItem(&ri);
QGraphicsView v(&s);
v.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
v.setFixedHeight(v.sceneRect().height() + (v.horizontalScrollBar()->height()));
v.show();
return qapp.exec();
}
Here is a patch for the issue:
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index a859b43..a3380de 100644
— a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -373,11 +373,11 @@ void QGraphicsViewPrivate::recalculateContentSize()
bool useHorizontalScrollBar = (viewRect.width() > width) && hbarpolicy != Qt::ScrollBarAlwaysOff;
bool useVerticalScrollBar = (viewRect.height() > height) && vbarpolicy != Qt::ScrollBarAlwaysOff;
- if (useHorizontalScrollBar && !useVerticalScrollBar) {
+ if (useHorizontalScrollBar && hbarpolicy != Qt::ScrollBarAlwaysOn && !useVerticalScrollBar) { if (viewRect.height() > height - scrollBarExtent) useVerticalScrollBar = true; } - if (useVerticalScrollBar && !useHorizontalScrollBar) {
+ if (useVerticalScrollBar && vbarpolicy != Qt::ScrollBarAlwaysOn && !useHorizontalScrollBar) { if (viewRect.width() > width - scrollBarExtent) useHorizontalScrollBar = true; }