Sorry but I still cannot crack it. I went with your advise and created a Widget in Creator and gave it the size I want the card area to have. In the code I initialize the cards:
cardVector.resize(8);
grid->setRowMinimumHeight(0,240);
grid->setRowMinimumHeight(1,240);
int k = 0;
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 4; ++j){
cardVector[k] = new Card;
cardVector[k]->index = k;
[...]
grid->addWidget(cardVector[k], i, j);
k++;
}
}
ui->cardContainer->setLayout(grid);
cardVector.resize(8);
QGridLayout *grid = new QGridLayout;
grid->setRowMinimumHeight(0,240);
grid->setRowMinimumHeight(1,240);
int k = 0;
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 4; ++j){
cardVector[k] = new Card;
cardVector[k]->index = k;
[...]
grid->addWidget(cardVector[k], i, j);
k++;
}
}
ui->cardContainer->setLayout(grid);
To copy to clipboard, switch view to plain text mode
This works fine but redoing it does not work.
cards.removeAt(activeIndex);
cardIndex--;
cardVector.removeAt(activeIndex);
int k = 7;
cardVector.resize(8);
cardVector[k] = new Card;
[...]
// redoing the vector
for(int k = 0; k < fighterIndex; ++k){
card
[k
].
name = card
[k
].
type+" "+QString::number(k
+1);
cardVector[k]->setTitle(card[k].name);
updateCard(k);
}
// Redoing the layout
while((item = ui->cardContainer->layout()->takeAt(0)) != NULL ){
delete item->widget();
delete item;
}
delete ui->cardContainer->layout();
grid->setRowMinimumHeight(0,240);
grid->setRowMinimumHeight(1,240);
k = 0;
for(int i = 0; i< 2; ++i){
for(int j = 0; j<4;++j){
cardVector[k]->index = k;
grid->addWidget(cardVector[k], i, j); // <- at this line the program crashes
k++;
}
}
ui->cardContainer->setLayout(grid);
}
cards.removeAt(activeIndex);
cardIndex--;
cardVector.removeAt(activeIndex);
int k = 7;
cardVector.resize(8);
cardVector[k] = new Card;
[...]
// redoing the vector
for(int k = 0; k < fighterIndex; ++k){
card[k].name = card[k].type+" "+QString::number(k+1);
cardVector[k]->setTitle(card[k].name);
updateCard(k);
}
// Redoing the layout
QLayoutItem* item;
while((item = ui->cardContainer->layout()->takeAt(0)) != NULL ){
delete item->widget();
delete item;
}
delete ui->cardContainer->layout();
QGridLayout *grid = new QGridLayout;
grid->setRowMinimumHeight(0,240);
grid->setRowMinimumHeight(1,240);
k = 0;
for(int i = 0; i< 2; ++i){
for(int j = 0; j<4;++j){
cardVector[k]->index = k;
grid->addWidget(cardVector[k], i, j); // <- at this line the program crashes
k++;
}
}
ui->cardContainer->setLayout(grid);
}
To copy to clipboard, switch view to plain text mode
I do not see what is different from the first part. Why does the program crash when I add a widget to the layout here? The code is identical to the first one, isn't it? What can I do to find the problem?
Thanks for the help!
Bookmarks