Qt World Summit: Submit your Presentation

Setting contentMargins for a QScrollArea?

  • Hi,

    I'm trying to set contentMargins to a QScrollArea, 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->wGroupContainer = new QWidget;
        this->layoutGroupContainer = new QHBoxLayout;

    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, that setContentsMargins() 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!

  • Lifetime Qt Champion


    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.

Log in to reply