Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting contentMargins for a QScrollArea?
Qt 6.11 is out! See what's new in the release blog

Setting contentMargins for a QScrollArea?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 643 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Binary91 0
    wrote on last edited by Binary91 0
    #1

    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->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, 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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      No, QScrollArea use is through setWidget, so it's rather un that one that you should do your customization.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        No, QScrollArea use is through setWidget, so it's rather un that one that you should do your customization.

        B Offline
        B Offline
        Binary91 0
        wrote on last edited by
        #3

        @SGaist Thank you, it works now with applying the settings to the QWidget.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved