How do I dynamically add QPushButtons to dynamically added QGroupBoxes? Here is my code (inside a childwindow) which dynamically adds Groupboxes along with their PushButtons. Onclick of one of these PushButtons there must be added PushButtons inside the belonging GroupBox. But how to place them inside the GroupBox?
void MyWidget
::systemButton(QGroupBox *groupBox
[]) {
systemcounter += 1;
btnGtr
->setText
(QString("Guitar: %1").
arg(systemcounter
));
vbox->addWidget(btnGtr);
groupBox->setLayout(vbox);
mainLayout->addWidget(groupBox);
QObject::connect(btnGtr,
SIGNAL (clicked
()),
this,
SLOT (handleButton
()));
}
void MyWidget::on_addbutton_clicked()
{
pagecounter += 1;
btnTest
->setText
(QString("Test: %1").
arg(pagecounter
));
top->addWidget(groupBox);
top->addWidget(btnTest);
top->maximumSize();
mainLayout->addLayout(top);
QObject::connect(btnTest,
SIGNAL (clicked
()),
this,
SLOT (systemButton
()));
}
void MyWidget::systemButton(QGroupBox *groupBox[])
{
systemcounter += 1;
QPushButton *btnGtr = new QPushButton();
btnGtr->setText(QString("Guitar: %1").arg(systemcounter));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(btnGtr);
groupBox->setLayout(vbox);
mainLayout->addWidget(groupBox);
QObject::connect(btnGtr, SIGNAL (clicked()), this, SLOT (handleButton()));
}
void MyWidget::on_addbutton_clicked()
{
pagecounter += 1;
QHBoxLayout *top = new QHBoxLayout;
QGroupBox *groupBox = new QGroupBox(tr("&Page 1"));
QPushButton *btnTest = new QPushButton();
btnTest->setText(QString("Test: %1").arg(pagecounter));
top->addWidget(groupBox);
top->addWidget(btnTest);
top->maximumSize();
mainLayout->addLayout(top);
QObject::connect(btnTest, SIGNAL (clicked()), this, SLOT (systemButton()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks