Help with ScrollArea
-
I am back again, and so close to having it working properly.
I am creating a QFrame with a QFormLayout and I dynamically add labels and edit fields . It works well until I try and add more than will fit, at which time it increases my MainWindow height. This is OK unless someone attempts to have a form that exceeds to available screen height.
In my quest to make it scrollable, like the QTreeWidget I am close but no prize. If I add more nodes to the QTreeWidget it simply creates a scrollbar and does the "right thing".
With the QForm it expands the Mainwindow.
QFrame * formFrame = new QFrame ();
QFormLayout* layout = new QFormLayout(formFrame);
formFrame->setLayout(layout);I have this code for the ScrollArea attempt, where it attempts to make the excess rows fit by squishing everything. No scrollbars appear.
QFrame* formFrame = new QFrame();
QScrollArea* ScrollArea = new QScrollArea(formFrame);
ScrollArea->setWidgetResizable (true);
ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QFormLayout* layout = new QFormLayout(ScrollArea);Here are some pictures of the simple
and using ScrollArea
-
@kshegunov Yes, sir it works.
I had 2 things wrong. I was setting the ScrollArea into the layout, That needs to be the form, ie formFrame and I needed to set the ScrollArea widget after I put all of my data into the layout.
QFrame* formFrame = new QFrame();
QScrollArea* ScrollArea = new QScrollArea(); //formFrame);
ScrollArea->setWidgetResizable (true);
ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);QFormLayout* layout = new QFormLayout(formFrame);
// a whole bunch of statements that fill a label and text box and
// put them to the layout as a row.
// then this bit of magicScrollArea->setWidget(formFrame);
And the result is this
Thank you SO VERY MUCH. I spent a few days going forward and backward and sometimes sideways for a change.
-
QWidget * container = new QWidget(); QFormLayout * layout = new QFormLayout(container); // ... fill up the layout scrollArea->setWidget(container); //< Must be after the layout's been added to the container widget
Here's a complete example.
-
@kshegunov Yes, sir it works.
I had 2 things wrong. I was setting the ScrollArea into the layout, That needs to be the form, ie formFrame and I needed to set the ScrollArea widget after I put all of my data into the layout.
QFrame* formFrame = new QFrame();
QScrollArea* ScrollArea = new QScrollArea(); //formFrame);
ScrollArea->setWidgetResizable (true);
ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);QFormLayout* layout = new QFormLayout(formFrame);
// a whole bunch of statements that fill a label and text box and
// put them to the layout as a row.
// then this bit of magicScrollArea->setWidget(formFrame);
And the result is this
Thank you SO VERY MUCH. I spent a few days going forward and backward and sometimes sideways for a change.