Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3830

The width of the scrollbar is not computed correctly if one of the QScrollBar is always visible. [patch]

    XMLWordPrintable

Details

    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; }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes