Scroll area is smaller than dialog
-
wrote on 9 Feb 2016, 05:54 last edited by
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(titleRow); layout->addRow (spacer_Label,spacer_Label); layout->addRow (Label_ID,ID_Display); layout->addRow (NameRow); }
It produces the following dialog:
Image
Please help me to find out why the scrolling area is smaller than the dialog.
Thank you. -
wrote on 9 Feb 2016, 09:32 last edited by Ni.Sumi 2 Sept 2016, 10:20
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 );
Dialogname->setlayout(sam) -
wrote on 9 Feb 2016, 14:39 last edited by
Thank you. It worked well.
-
wrote on 10 Feb 2016, 04:28 last edited by
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. -
wrote on 10 Feb 2016, 09:05 last edited by
Hi @gabor53 ,
Till it works fine..no 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.
-
wrote on 10 Feb 2016, 13:51 last edited by
Thank you.
3/7