0

Stacked Widgets don't have the possibility to update the size to the minimum size of the contents current shown. It always shows the biggest size of the biggest layer and stays there as long as the QSizePolicy stays the same.

An aproach i found long time ago was to use a function like this:

void SmartUIWrapper::updateStackedWidgetSize( QStackedWidget* stacked, int index )
{
  // Set to size policy ignored for the rest of pages. Set expanding to the actual one
  for (int i = 0; i < stacked->count (); ++i)
  {
    // determine the vertical size policy
    QSizePolicy::Policy policy = QSizePolicy::Ignored;
    if (i == index) 
      policy = QSizePolicy::Expanding;

    // update the size policy
    stacked->widget (i)->setSizePolicy(QSizePolicy::Fixed, policy);
  }
}

It sets all elements to Ignored, and then it sets the vertical policy of the selected widget which is Expanding (or whatever you want).

Later on i found out that reloading the styletheet updates the current sizes and makes the widget to resize to the minimum. But this approach is way too slow and unnecessary.

Do you know any other way to update the size to shrink to the smallest size in the current layer shown?

4

0 回答 0