Resize QStackedWidget to Page

I want my QStackedWidget resize to the page being opened.

I got a lot of widgets attached to the first page, but on the other pages there is only one button. Therefore, they remain so large, and the first page is fine.

How to make my QStackedWidget size of the page being viewed.

The reason I want to do this is because I have three different options, and after that I have other things. If I go into a mode where there is a button and then a lot of free space, I do not understand why this does not change.

+2
source share
3 answers

You can use this Resizable StackedWidget

In my practice, I remember that I had a class derived from QStackedWidget with an overridden addWidget method. In this method, I did the following:

 void ResizableStackedWidget::addWidget(QWidget* pWidget) { pWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); QStackedWidget::addWidget(pWidget); } 

And connected to the currentChange signal (QWidget *) with this slot:

 void ResizableStackedWidget::onCurrentChanged(int index) { QWidget* pWidget = widget(index); Q_ASSERT(pWidget); pWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); pWidget->adjustSize(); adjustSize(); } 
+3
source
 // make the stacked widget size to the current page only for (int i = 0; i < m_ui->stackedWidget->count (); ++i) { // determine the vertical size policy QSizePolicy::Policy policy = QSizePolicy::Ignored; if (i == m_ui->stackedWidget->currentIndex ()) policy = QSizePolicy::Expanding; // update the size policy QWidget* pPage = m_ui->stackedWidget->widget (i); pPage->setSizePolicy (policy, policy); } 
+5
source

You can wrap pages with a single button in a vertical layout QFrame and add a separator at the bottom.

+1
source

All Articles