Important: Please read the Qt Code of Conduct -

Scroll area is smaller than dialog

  • Hi,
    I have the following scroll area:

    QScrollArea *scroll = new QScrollArea(this);
        scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
        scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
        QWidget *viewport  = new QWidget(this);
        scroll->setWidget (viewport);
        scroll->setWidgetResizable (true);
        QFormLayout *layout = new QFormLayout(viewport);
        viewport->setLayout (layout);
        layout->setSpacing (60);
    // Title Row setup
        QHBoxLayout *titleRow = new QHBoxLayout(viewport);
        titleRow->addWidget (Title);
    //Creating the Name row
        QHBoxLayout *NameRow = new QHBoxLayout(viewport);
                    NameRow->addWidget (Label_Name);
                    NameRow->addWidget (LineEdit_Name);
                    NameRow->addSpacing (10);
                    NameRow->addWidget (angry_image_Label);
                    NameRow->addSpacing (10);
                    NameRow->addWidget (incorrect_Label);
            		NameRow->addSpacing (350);
    // Interspace
        layout->setVerticalSpacing (30);
        QLabel *spacer_Label = new QLabel;
    // Displaying the rows
        layout->addRow (spacer_Label,spacer_Label);
        layout->addRow (Label_ID,ID_Display);
        layout->addRow (NameRow);

    It produces the following dialog:
    Please help me to find out why the scrolling area is smaller than the dialog.
    Thank you.

  • Hi @gabor53

    Set Grid-layout in the Dialog. Make Gridlayout inside the Dialog for the Scrollarea.Roughly the design of widgets looks like this.

    Dialog ( gridlyout ( Scrollarea( layout( yourwidget's)))) .

    Add this..
    QGridLayout *sam = new QGridLayout;
    sam->addWidget(your scrollarea );

  • Thank you. It worked well.

  • Hi @gabor53

    Okay. Please set it as solved . :)

  • Just an other related question: Do I need to worry about this message:

    "QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout"?
    Thank you.

  • Hi @gabor53 ,

    Till it works problem :)

    Yes that warning is from the HLaoyuts in the viewport. Why you have need 2 HLayouts in the viewport? You can add "title row widget" in the "NameRow" QHBoxLayout. Or use QGridLaoyut with stretching.

  • Thank you.

Log in to reply