Column::Column(QWidget *parent)
: QListWidget(parent)
{
Button *button = new Button(this);
{
connect(button, &Button::clicked,
this, &Column::slot_addCard);
}
QListWidgetItem *buttonItem = new QListWidgetItem(this);
buttonItem->setSizeHint(button->sizeHint()); // change size
addItem(buttonItem);
setItemWidget(buttonItem, button);
qDebug() << buttonItem;
qDebug() << button;
}
void Column::slot_addCard()
{
const int COUNT = this->count() - 1;
Button *button = dynamic_cast<Button*>(itemWidget(item(COUNT)));
QListWidgetItem *buttonItem = this->takeItem(COUNT);
qDebug() << buttonItem;
qDebug() << button;
Card *card = new Card(this);
QListWidgetItem *cardItem = new QListWidgetItem(this);
cardItem->setSizeHint(card->sizeHint());
setItemWidget(cardItem, card);
addItem(buttonItem);
setItemWidget(buttonItem, button); // Segmentation fault !!!
}