PDA

View Full Version : Adding widgets to QScrollArea



ser_bur
16th May 2007, 19:43
Hi, guys.
Need some help...
The task is following: I need to place into QGroupBox some number of widgets - for example, QLabel. After filling this QGroupBox scrollbar must appear.
Code is next:



extGroupLayout = new QVBoxLayout;
groupBoxLayout = new QVBoxLayout;
scrollArea = new QScrollArea(this);

groupBox->setLayout(extGroupLayout);
extGroupLayout->addWidget(scrollArea);
scrollArea->setLayout(groupBoxLayout);

for(i=0;i<20;i++)
{
// Let's make our checkboxes...
IDCheckbox[i] = new QCheckBox;
groupBoxLayout->addWidget(IDCheckbox[i]);
}


After executing, checkboxes get minimal possible height, ignoring value, set by setMinimalHeight method; last of them are hiding behind the edge of scroll area, but scrolling is still impossible :mad:

Where is my problem? Don't say it is in my head :o

marcel
16th May 2007, 20:00
Do this:

- Set this group box as the scroll area widget via QScrollArea::setWidget. You don't need to set a layout in the scroll area.
- Add all the widgets you need to add to your group box.

Be careful, because you may need to set some minimum sizes there ( for the scroll area, for example ).

Regards

ser_bur
16th May 2007, 20:35
Well, i tried, but result is the same. Main detail is that i must add widgets not directly to GroupBox, but to layout: real interface is much more complicated than just column of checkboxes, as in example. I think this is a reason... Is there a possibility to use layout in this case without "compressing" added widgets?..

UPD: here is what i have at the moment:
http://img442.imageshack.us/img442/4541/scrollareawb3.png

marcel
16th May 2007, 21:11
You hould have this:

QScrollArea <- QGroupBox <- a layout (whatever you need ) <- widgets ( created with the group box as parent and added to the layout ).

You also should set the size of the group box to match the QScrollArea's viewport size.

Regards

ser_bur
17th May 2007, 07:12
After some playing with sizes, finally I've got scroll as expected :). But height of widgets still stays minimal, ignoring CheckBox->setMinimumHeight() and groupBoxLayout->setRowMinimumHeight() methods :(

marcel
17th May 2007, 07:26
Make sure you created all the widgets with a parent ( the group box ).

phillip_Qt
19th August 2013, 10:38
After some playing with sizes, finally I've got scroll as expected :). But height of widgets still stays minimal, ignoring CheckBox->setMinimumHeight() and groupBoxLayout->setRowMinimumHeight() methods :(

Hi,

can you please tell me how you did this? I want to implement same thing for my application.