Hello,
I created some labels and buttons dynamically. I want to know how can I handle each button when it's clicked.
I know in a normal way for one button it goes like this:
Qt Code:
  1. void test::on_btnName_clicked()
  2. {
  3. // Some code here ....
  4. }
To copy to clipboard, switch view to plain text mode 
So what abt this case ?
I have no idea so here's what I've done so far
test.cpp
Qt Code:
  1. #include "test.h"
  2. #include "ui_test.h"
  3.  
  4. test::test(QWidget *parent) : QMainWindow(parent), ui(new Ui::test)
  5. {
  6. ui->setupUi(this);
  7. for (int i = 1; i <= 4; i++){
  8.  
  9. for (int j = 1; j <= 4; j++){
  10. QString btnName = "Button "+QString::number(i)+","+QString::number(j);
  11. QString lblName = "Label "+QString::number(i)+","+QString::number(j);
  12. QPushButton* panelButton = new QPushButton(btnName);
  13. QLabel* label = new QLabel(lblName);
  14. panelButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  15. label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  16. ui->PanelButtonGridLayout->addWidget(panelButton,i,4);
  17. if(j<4) {
  18. ui->PanelButtonGridLayout->addWidget(label,i,j);
  19. }
  20. }
  21. }
  22. }
  23.  
  24. test::~test()
  25. {
  26. delete ui;
  27. }
To copy to clipboard, switch view to plain text mode