Solved Setting contentMargins for a QScrollArea?
-
Hi,
I'm trying to set
contentMargins
to aQScrollArea
, so that its corresponding QWidget is displayed with a specific distance to the QScrollArea itsself.The code:
this->saGroupContainer = new QScrollArea; this->saGroupContainer->setContentsMargins(10,10,10,10); // <-- doesn't have any effect this->saGroupContainer->setBackgroundRole(QPalette::Base); this->wGroupContainer = new QWidget; this->wGroupContainer->setBackgroundRole(QPalette::Dark); this->layoutGroupContainer = new QHBoxLayout; this->layoutGroupContainer->setSizeConstraint(QLayout::SetMinAndMaxSize); this->wGroupContainer->setLayout(this->layoutGroupContainer); this->saGroupContainer->setWidget(this->wGroupContainer);
The QWidget of the QScrollArea has a dark backgroundRole and I'd like to have it shown with a distance of 10px to the QScrollArea border. Unfortunatelly, setting contentMargins to the QScrollArea has no effect. Is there a reason for it?
Instead, setting contentMargins to the QWidget is possible, but that is not the wished behaviour since I'd like to show the QWidget itsself with a specific distance to the Frame. Maybe it is true, thatsetContentsMargins()
only has an effect to layouts? If yes, how could I manage this here since QScrollArea has not the expected behaviour I'd like it to have when I add a layout to it (don't even know if that was correct style to set a layout to a QScrollArea...).Any ideas? Thank you!
-
Hi,
No, QScrollArea use is through setWidget, so it's rather un that one that you should do your customization.
-
@SGaist Thank you, it works now with applying the settings to the QWidget.