I have a UIForm named "Spell" that contains inter alia QGridLayout with custom widgets named "PElement". The amount of PElement widgets depends on number of spells in my database. So, I fill QGridLayout by ui->spellLayout->addWidget(...)
When PElement is clicked it emits signal. I need to connect each of PElement in QGridLayout with slot in Spell class. I have no idea how to do it. Thanks for help!
@edit
this is a function that add PictureElement to QGridLayout
void Spells::setSpellList(QString lore)
{
QList<QStringList> elementList = Database::instance()->getSpellElement(lore);
while(ui->spellLayout->count() > 0) {
QWidget *w = ui->spellLayout->itemAt(0)->widget();
ui->spellLayout->removeWidget(w);
delete w;
}
int w,h;
w = 162;
h = 203;
int maxCol = ui->spellScrollArea->width() / (w + ui->spellLayout->spacing());
if(maxCol<=0) {
Indicator::instance()->hide();
return;
}
foreach(QStringList list, elementList){
PictureElement *spellElement = new PictureElement;
spellElement->setText(list.at(0));
spellElement->setPixmap(list.at(1));
spellElement->setMinimumSize(w, h);
ui->spellLayout->addWidget(spellElement,
ui->spellLayout->count() / maxCol,
ui->spellLayout->count() % maxCol);
spellElement->show();
}
Indicator::instance()->hide();
}
What I want: connect every PictureElement (SIGNAL clicked) from QGridLayout with slot in Spells class.