I have a QVBoxLayout as a pointer in my window and want to add Widgets dynamically (When the user presses a button, a Widget is added to the VBoxLayout). The VBoxLayout is set as Layout in the ScrollArea. But if I add Widgets to the VBoxLayout, the size of the VBoxLayout does not change and everything gets crumpled.
m_ControlsLayout = new QVBoxLayout; //A member variable to add things later
{
QPushButton *PushButton = new QPushButton(tr("Add a new control"));
connect(PushButton, SIGNAL(clicked()), this, SLOT(addControl())); //Adds it
m_ControlsLayout->addWidget(PushButton, 1);
}
for(int i=0;i<10;i++) //I am adding 10 useless Widgets to fill the space
addControl();
QScrollArea *ScrollArea = new QScrollArea;
connect(this)
ScrollArea->setWidget(Layout2Widget(m_ControlsLayout));
The addControl() Slot just adds a Widget:
m_ControlsLayout->addWidget(new ControlWidget);
I think I have to tell the QScrollArea that it should update its heights.
scrollArea->setWidgetResizable(true)
? – thuga