Answer the question
In order to leave comments, you need to log in
How to re-add a custom widget?
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 !!!
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question