Solved Addition QCheckBoxes to QScrollArea
-
Hi. How correctly to do this?
QWidget materialContainer; QVBoxLayout *materialLay = new QVBoxLayout(this); materialContainer.setLayout(materialLay); ui->_materialScrollArea->setWidget(&materialContainer); foreach(NodePtr ptr, _materialModel->allItems()) { Material *entity = ptr.data()->item().value<Material*>(); QCheckBox *chBox = new QCheckBox(entity->name()); materialLay->addWidget(chBox); }
Where did I go wrong? I need for each entity QCheckBox.
-
@Evgeny-Siberia said in Addition QCheckBoxes to QScrollArea:
QVBoxLayout *materialLay = new QVBoxLayout(this);
materialContainer.setLayout(materialLay);This is wrong. The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.
QVBoxLayout *materialLay = new QVBoxLayout(&materialContainer)
Apart from this - how long do you think does materialContainer live?
-
@Evgeny-Siberia said in Addition QCheckBoxes to QScrollArea:
QVBoxLayout *materialLay = new QVBoxLayout(this);
materialContainer.setLayout(materialLay);This is wrong. The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.
QVBoxLayout *materialLay = new QVBoxLayout(&materialContainer)
Apart from this - how long do you think does materialContainer live?
-
@Christian-Ehrlicher said in Addition QCheckBoxes to QScrollArea:
The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.
IIRC,
setLayout
re-"parents" the layout, so that after this line thematerialContainer
-QWidget
is the new parent ofmaterialLayout
.
((this)
is still not necessary and can be removed).Change
QWidget materialContainer
toQWidget* materialContainer = new QWidget;
then remove the
&
insetWidget
and it should work (cant tell if the rest is ok). -
Apart from this - how long do you think does materialContainer live?
kid error
IIRC,
setLayout
re-"parents" the layoutyou are right
Thank you all!