Important: Please read the Qt Code of Conduct -

Calling updateGeometry() in resizeEvent() causes segFault when QScrollArea scrollbar does not exist

  • I have a QScrollArea with a list of widgets inside (using a Horizontal Box Layout).

    The QScrollArea is the lower half of a vertical splitter, and when I increase the height of the scroll area, the contents adjust their width to maintain a square apsect ratio. I achieve this by overriding the resizeEvent()

    @ QSize WidgetSpriteFrameView_Frame::sizeHint() const

        return hint;

    void WidgetSpriteFrameView_Frame::resizeEvent(QResizeEvent * e)

    hint = QSize(height(),height());


    The size policy is (QSizePolicy::Fixed,QSizePolicy::MinimumExpanding).

    This seems to work great, but only when there is a scroll bar on the scroll view. Look carefully at the following GIF for a demonstration:

    As you can see, it crashes right as the scroll bar is taken away. If I set the scrollbar to ScrollBarAlwaysOn, then everything works, but this is ugly and I would like to have it set to ScrollBarAsNeeded.

    The segmentation occurs when updateGeometry(); is called.

    Any advice on how to fix this?

Log in to reply