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

QAbstractScrollArea doesn't account for scrollbar margins when setting viewport geometry

    XMLWordPrintable

Details

    • Linux/X11

    Description

      When using a sub-class of QAbstractScrollArea (such as QGraphicsView), the viewport geometry doesn't account for margins on visible scrollbars.

      The viewport geometry is set in QAbstractScrollAreaPrivate::layoutChildren_helper(). In this function, the implementation does seem to account for the visible scrollbars (it deducts the space required for the scrollbars, from the viewport size). However, this seems to based off of the size of the scrollbar widgets and so it doesn't include any margins applied via QStyleSheetStyle.

      Looking at the implementation for version 6.1.2, the problem seems to lie in the following code:

      const int hsbExt = hbar->sizeHint().height();
      const int vsbExt = vbar->sizeHint().width();
      
      ...
      
      QPoint cornerOffset((needv && vscrollOverlap == 0) ? vsbExt : 0, (needh && hscrollOverlap == 0) ? hsbExt : 0);
      
      ...
      
      controlsRect = q->contentsRect();
      viewportRect = QRect(controlsRect.topLeft(), controlsRect.bottomRight() - cornerOffset);
      
      

      The above code deducts the size of the visible scrollbars from the viewport, but not the margins applied via a stylesheet (QSS).

      To replicate:

      • Create a QGraphicsView with a scene.
      • Ensure the vertical and horizontal scrollbar policies are set to ScrollBarAsNeeded.
      • Set the sceneRect width to the width of the QGraphicView viewport (meaning no horizontal scrollbar should be required).
      • Set the sceneRect height to some large value that exceeds the height of the viewport (meaning a vertical scrollbar is visible).
      • Run the program and confirm that everything works as expected (vertical scrollbar is visible, horizontal scrollbar is not)
      • Now apply a margin via a QSS style, to the vertical scrollbar (via QGraphicsView::verticalScrollbar()->setStyleSheet(...))
      • Run the program again and confirm that a horizontal scrollbar has now appeared, as the sceneRect width (which is equal to the viewport width) exceeds the available space in the QAbstractScrollArea.

      To clarify; after following the above steps, the issue arises because we set the sceneRect width to the width of the viewport, but the width of the viewport doesn't account for the stylesheet margins of the vertical scrollbar (so the width is too large), which is why the horizontal scrollbar now appears (as the width of the sceneRect exceeds the available space).

      The issue was produced on Linux/X11, with Qt version 6.1.2, but other versions are likely to be affected.

      Apologies if I have misunderstood something here. This is my first Qt bug report and I haven't had much exposure to Qt's implementation code

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            navnav Nav Mohammed
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes