【发布时间】:2015-09-23 21:10:37
【问题描述】:
我有一个名为“Spell”的 UIForm,其中包含 QGridLayout 以及名为“PElement”的自定义小部件。 PElement 小部件的数量取决于我的数据库中的法术数量。所以,我用ui->spellLayout->addWidget(...)填充QGridLayout
当 PElement 被点击时,它会发出信号。我需要将 QGridLayout 中的每个 PElement 与 Spell 类中的插槽连接起来。我不知道该怎么做。 感谢您的帮助!
@编辑
这是一个将 PictureElement 添加到 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();
}
我想要的: 将 QGridLayout 中的每个 PictureElement(单击的信号)与 Spells 类中的插槽连接起来。
【问题讨论】:
-
我认为您需要提供更多代码。不太清楚你在问什么。
-
我更新了我的问题; )
标签: qt signals-slots qgridlayout