Can QLayout hide rather than resize QWidgets?

I am trying to implement a user interface element consisting of many sub-elements. They can grow or contract, as the parent does. Pretty simple QLayout stuff. However, when the parent becomes too small, it hides several sub-elements (this means that now there is more space left for the remaining elements, and they are a bit more).

I see no way to handle this standard QLayout . I think you could think of child widgets as priority, and hidden ones with low priority.

The layout is strictly horizontal, so it is vaguely similar to a toolbar, except that there is no way to get to hidden elements. (And the children are not actions, as they will be in the QToolBar).

+4
source share
1 answer

Take a look at the QStackedWidget. I just started using them myself.

They have β€œpages” that are shown / hidden when called. For instance:

ui.stackedWidget->setCurrentIndex( 0 );

For example, when index 0 is displayed, pages 1,2,3 ... are hidden under it.

I connected to a bunch of switches that, when clicked, displayed the corresponding page / widgets and hid others below it. The connection is simple:

 connect( button_group_ptr, SIGNAL( buttonClicked( int ) ), ui.stackedWidget, SLOT( setCurrentIndex( int ) ) ); connect( ui.stackedWidget, SIGNAL( currentChanged( int ) ), this, SLOT( stackedWidgetChanged( int ) ) ); 
0
source

Source: https://habr.com/ru/post/1394454/


All Articles