1 Attachment(s)
Scrollbar covers Labels in ScrollArea
Hi,
I have a ScrollArea with many groupboxes which contain Checkboxes. But it seems like the size of the ScrollArea does not adapt to the layout.
Code:
ui->scrollAreaWidgetContents->setLayout(verticalLayoutForWidget);
QGroupBox *TypeGroupBox
[NumberOfAvailableTypes
];
for (int i = 0; i < NumberOfAvailableTypes; i++){
TypeGroupBox
[i
] = new QGroupBox(ui
->AvailableDataScrollArea
);
TypeGroupBox[i]->setTitle(AllData.at(i)->NameWithoutNumber());
QCheckBox *DataCheckbox
[AllData.
at(i
)->quantity
()];
QHBoxLayout* horizontalLayout
[AllData.
at(i
)->quantity
()];
for (int j = 1; j <= AllData.at(i)->quantity(); j++){
DataCheckbox
[j
] = new QCheckBox(TypeGroupBox
[i
]);
DataCheckbox[j]->setText(AllData.at(i)->NameWithNumber());
horizontalLayout[j]->addWidget(DataCheckbox[j]);
verticalLayout[i]->addLayout(horizontalLayout[j]);
}
}
verticalLayoutForWidget->addWidget(TypeGroupBox[i]);
}
Re: Scrollbar covers Labels in ScrollArea
The scroll bar adapts to the size of the content widget (scrollAreaWidgetContents I assume) but that size is not changing here. Packing widget into its layout will, in general, not change the containers size. Try setting the vertical size policy of scrollAreaWidgetContents to Fixed so it is forced to match the aggregate of the contents vertical size hints.
Re: Scrollbar covers Labels in ScrollArea
SizePolicy of scrollAreaWidgetContents is horizontal and vertical: fixed now
SizePolicy of ScrollArea is horizontal: preferred; vertical: expanding
sizeAdjustPolicy: AdjustToContens
When I set the horizontal ScrollBar ScrollBarAsNeeded it seems to work. But I dont want to have a horizontal ScrollBar. I want the ScrollArea to expand horizontal when it's layout changes.
Re: Scrollbar covers Labels in ScrollArea
It still does not work. :(
Re: Scrollbar covers Labels in ScrollArea
You want the QScrollArea to abandon its reason for existing and grow to accomodate its content. That is precisely what it is designed not to do. The scroll area gets the space allocated to it by its parent layout/widget and allows you to display an arbitrary sized widget within that space, using scrollbars as needed.
To defeat the default behaviour you have to do the work. When the contentsWidget() changes size you must manually change (force) the horizontal dimension of the QScrollArea to accomodate the contained widget's width plus a margin and width for a vertical scroll bar if one is present.