Important: Please read the Qt Code of Conduct -

Increase spacer size when scrollbar disappears

  • Hi !

    I am relatively new to Qt developpement, and i would like to ask you a question about a problem of UI design i encountered.
    I have a widget where there is a vertical layout composed of a QFrame (1) and a Spacer (3). In the QFrame there are 3 QFrame (4, 5, and 6) of fixed size, and a QScrollArea (2.) inside a QFrame.


    The behaviour i want is the following : when the scrollbar is shown, the spacer is hidden, and when the main widget's size is increased :

    • if the scroll bar is still shown, the height of the widget surrounding the QScrollArea is increased, and the QScrollArea is expanded
    • if the scroll bar is hidden (the QScrollArea is entierly displayed), this is the size of the spacer that grows to occupy all the remaining space.

    It seems to me that this behaviour need to be programatically specified. I tried various solutions but i had no success for the moment. Are there anyone here who could help me find a good way to implement the behaviour i want?

    Thank you in advance !

  • I found a potential solution but for it to work, i need to get the total size of the widget contained in the scroll area. Are there any function to obtain this piece of information?

Log in to reply