Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-335

Phantom Margin and incorrect resizeEvent reported size for QAbstractScrollArea

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P4: Low
    • 6.0
    • 1.2.x
    • PySide
    • Windows 7 64-bit
      Python 3.4.4
      Pyside was installed by invoking "pip install PySide", which gave me version 1.2.4

    Description

      Troubleshooting I did
      QAbstractScrollArea appears to have a 1 pixel wide margin around the viewport that can't be removed. This becomes apparent when overriding resizeEvent and having it print the QResizeEvent.size(). If the size of the QAbstractScrollArea is set to 200x200, this will report 198x198 on the initial resize, which seems to go against the specification of resizeEvent: "Returns the new size of the widget. This is the same as QWidget.size() ."

      At first it seems these are widget content margins, because calling QAbstractScrollArea.contentsMargins() will return margins of 1, 1, 1, 1. However, changing them with QAbstractScrollArea.setContentsMargins() will change this reported value, but this doesn't affect the reported size of resizeEvent(), nor will it do anything to the margins.

      resizeEvent() seems to report the size of the viewport instead of the actual QAbstractScrollArea. I'm not sure if this is intentional or not, but I didn't see it in the docs (and QWidget isn't affected by margins in this way.) Regardless, the 1-pixel margin isn't specified in the docs. I can see it if I look closely however.

      Resizing the viewport with QAbstractScrollArea.viewport().setFixedSize(180,180) reveals another 1-pixel margin, colored white, normally covered by the viewport. This is also revealed if the margins around the viewport are increased with QAbstractScrollArea.setViewportMargins(5,5,5,5)

      The issue can be solved by calling QAbstractScrollArea.viewport().setGeometry(0,0,200,200) in the resizeEvent function. This resizes the viewport to match the QAbstractScrollArea and moves it to (0,0). However, this took awhile to figure out, and is a hacky solution. If the behavior I've talked about isn't changed, it should atleast be noted in the docs.

      Results: Issues in summary (tl;dr):
      1. QResizeEvent.size() from resizeEvent for QAbstractScrollArea reports the size of the viewport, instead of QAbstractScrollArea.size(), which conflicts with the docs for QResizeEvent.size(), which say "Returns the new size of the widget. This is the same as QWidget.size() ."

      2. There are two 1-pixel wide margins, the outer one gray, the inner one white, that can't be removed short of manually resizing and moving the viewport to cover them up. The inner one is usually covered up by the viewport by default unless the viewport is resized or moved. They aren't mentioned in the docs.

      3. QAbstractScrollArea.contentsMargins() reports margins of (1,1,1,1), which seems to be causing the outer 1-px margin, even though calling QAbstractScrollArea.setContentsMargins() to change it doesn't do anything.

      4. This also affects QScrollArea.

      I've attached a test script that demonstrates the bugs. Feel free to play around with it. Here's an example output:

      called self.setViewportMargins(0, 0, 0, 0)
      
      self.contentsMargins(): 1 1 1 1
      called self.setContentsMargins(0, 0, 0, 0)
      self.contentsMargins(): 0 0 0 0
      
      ---Initial resize event---
      Old size: -1 -1
      Reported size: 198 198
      Actual size: 200 200
      Viewport size: 198 198
      

      Attachments

        1. PYSIDE-335-c++.tar.gz
          2 kB
        2. pyside-335-test.py
          2 kB
        3. test.py
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kkyzivat Keith Kyzivat
            user890234 No Thanks
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes