[Interest] how to reset the layout in QStackedWidget/QScrollArea

Alexander Semke alexander.semke at web.de
Wed May 27 14:20:30 CEST 2020


Hi,

I have the following situation in the code:

m_propertiesDock = new QDockWidget(this);
addDockWidget(Qt::RightDockWidgetArea, m_propertiesDock);

auto* sa = new QScrollArea(m_propertiesDock);
stackedWidget = new QStackedWidget(sa);
sa->setWidget(stackedWidget);
sa->setWidgetResizable(true);

m_propertiesDock->setWidget(sa);

Later, different widgets of different sizes are shown in the stacked widget.
The scroll area is used here to be able to show widgets that are bigger then
the currently available place in the application window.

Here an example for how it looks like:
https://labplot.kde.org/wp-content/uploads/2018/10/histogram_main_window.png

The properties dock widget is on the right hand side showing the widget with
the properties of the histogram and.

The problem now is that the widgets shown there have very different minimum
sizes and when switching from a small one to a big one and then back to the
small one, the whole available space left after the big widget is used also
for the small widget. This leads to the situation where the small widget is
unnecessarily stretched and the scroll bars are still visible which is
actually not needed in this case. The checkbox "visible" like on the
screenshot above is moved to the bottom of this available space and the user
has to scroll down also for small widgets after switching from a big widget.
This is how it looks like after such a switch:
https://imgur.com/a/F5mCDwi

So, I'm looking for a way to how squeze the stacked widget and maybe also the
scroll area to the minimum size of the currently shown widget so there is no
need to show the scroll bars in the scroll area. Can someboy please point me
into the proper direction?


Thanks and Regards,
Alexander




More information about the Interest mailing list