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,
setLayoutre-"parents" the layout, so that after this line thematerialContainer-QWidgetis the new parent ofmaterialLayout.
((this)is still not necessary and can be removed).Change
QWidget materialContainertoQWidget* materialContainer = new QWidget;then remove the
&insetWidgetand it should work (cant tell if the rest is ok). -
@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?
Apart from this - how long do you think does materialContainer live?
kid error
IIRC,
setLayoutre-"parents" the layoutyou are right
Thank you all!