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. QScrollArea : doesn't expand to parent size

QScrollArea : doesn't expand to parent size

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.5k 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
    Black Imp
    wrote on last edited by Black Imp
    #1

    I've a big issue with scroll area. I've already been able to make it work in a different class of the application I'm developing, after many tries. This time I can't find a way to make the scroll area extend to its parent height. It always keeps a minimum height , just enough to show the 2 buttons to scroll up and down and being able to see the content is correctly created. The content widget extends to contain the labels as it should.
    Main container is derives from QMdiSubWindow.
    The following code is extracted from constructor. Label creation is not: labels are actually added at runtime.

    QScrollArea * labelScrollArea;
    QWidget * spaceDivider;
    QWidget * labelContainer;
    QVBoxLayout * labelContainerLayout;
    QHBoxLayout * dividerLayout;
    QVBoxLayout * rightPanelLayout;
    QWidget * rightPanel;
    QWidget * leftPanel;
    QVBoxLayout * leftPanelLayout;
    
    
    spaceDivider = new QWidget();
    spaceDivider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    dividerLayout = new QHBoxLayout();
    spaceDivider->setLayout(dividerLayout);
    
    // plot on the left
    
    leftPanel = new QWidget();
    leftPanelLayout = new QVBoxLayout();
    leftPanel->setLayout(leftPanelLayout);
    
    //...
    
    // right panel
    rightPanel = new QWidget();
    rightPanel->setFixedWidth(labelFontSize * 20);
    rightPanel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    rightPanel->setStyleSheet("background-color:black;");
    
    rightPanelLayout = new QVBoxLayout();
    rightPanel->setLayout(rightPanelLayout);
    rightPanel->layout()->setAlignment(Qt::AlignCenter);
    
    labelScrollArea = new QScrollArea(rightPanel);
    labelScrollArea->setStyleSheet("background-color:grey;");
    labelScrollArea->setFixedWidth(labelFontSize * 20);
    labelScrollArea->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    labelScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    labelScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    labelScrollArea->setWidgetResizable(true);
    
    labelContainer = new QWidget();
    labelContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    labelContainerLayout = new QVBoxLayout();
    labelContainer->setLayout(labelContainerLayout);
    labelContainer->layout()->setAlignment( Qt::AlignTop );
    labelContainer->setContentsMargins(0, 0, 0, 0);
    
    labelScrollArea->setWidget(labelContainer);
    labelContainer->setMinimumHeight(0);
    
    // add to support widget
    //dividerLayout->addWidget(plot);
    dividerLayout->addWidget(leftPanel);
    dividerLayout->addWidget(rightPanel);
    
    // add support widget to subwindow
    setWidget(spaceDivider);
    
    for (int index = 0; index < 100; index++ )
    {
           QLabel * label = new QLabel(NULL);
            label->setFixedHeight(40);
            label->setFixedWidth(labelFont.pointSize() * 18);
            label->setFont(labelFont);
            QPalette palette = label->palette();
            palette.setColor(label->backgroundRole(), Qt::black);
            palette.setColor(label->foregroundRole(), Qt:white);
            label->setPalette(palette);
            label->setText("Test");
            labelContainerLayout->addWidget(label);  
    }
    

    Any idea to make it work? Thank you

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

      Hi and welcome to devnet,

      You are not putting labelScrollArea in any layout hence it won't follow anything except it's initial size.

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

      1 Reply Last reply
      1
      • B Offline
        B Offline
        Black Imp
        wrote on last edited by
        #3

        Thankyou very much! it worked as you suggested, by adding

        rightPanelLayout->addWidget(labelScrollArea);
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Great !

          Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

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

          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