QSpacerItem (inside a QWidget) is not shrinking inside a QScrollArea
-
Hello,
I have elements associated in the following sequence:
My_QDockWidget::setWidget(My_QScrollArea);
My_QScrollArea::setWidget(My_QWidget);
My_QWidget::setLayout(My_QStackedLayout);
My_QScrollArea::setWidgetResizable(true);I added couple of My_Child_QWidget's to the My_QStackedLayout, and each My_Child_QWidget has a vertical and a horizontal QSpacerItems.
The problem is that QSpacerItems in the My_Child_QWidget's are not shrinking and so the scroll bars always appears (even if not necessary).
How can I make the My_Child_QWidget's QSpacerItems shrinkable and make My_QScrollArea's scroll bars disappear?
I tried all of the size policies but none worked. Any help will be much appreciated.
Thanks in advance...
-
@soma_yarram
you can try this.But to give an exact answer to your problem you will need to show some more code.
-
Have a look at the sizes for the spacer items. For example:
// horizontal spacer example button_hspacer = new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Minimum); button_hlayout->addItem(button_hspacer); // vertical spacer example widget_vspacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding); widget_layout->addItem(widget_vspacer,10,0,1,3);
I have the sizes set to zero (0,0) but anything that is small will work. The spacers will grow as needed and I have noticed the the Qt designer tends to put the real size that the spacer occupies when you created the form which makes it use that much space regardless.
If this is not the reason then have a closer look at all the child widgets. I recently ran into a problem like this and found some child widget was the culprit.