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?


Qt Code:
  1. void MyWidget::systemButton(QGroupBox *groupBox[])
  2. {
  3. systemcounter += 1;
  4.  
  5. QPushButton *btnGtr = new QPushButton();
  6. btnGtr->setText(QString("Guitar: %1").arg(systemcounter));
  7. QVBoxLayout *vbox = new QVBoxLayout;
  8. vbox->addWidget(btnGtr);
  9. groupBox->setLayout(vbox);
  10.  
  11. mainLayout->addWidget(groupBox);
  12.  
  13. QObject::connect(btnGtr, SIGNAL (clicked()), this, SLOT (handleButton()));
  14. }
  15.  
  16. void MyWidget::on_addbutton_clicked()
  17. {
  18. pagecounter += 1;
  19. QGroupBox *groupBox = new QGroupBox(tr("&Page 1"));
  20. QPushButton *btnTest = new QPushButton();
  21. btnTest->setText(QString("Test: %1").arg(pagecounter));
  22.  
  23. top->addWidget(groupBox);
  24. top->addWidget(btnTest);
  25.  
  26. top->maximumSize();
  27.  
  28. mainLayout->addLayout(top);
  29.  
  30. QObject::connect(btnTest, SIGNAL (clicked()), this, SLOT (systemButton()));
  31. }
To copy to clipboard, switch view to plain text mode