运行效果
关键代码:
- dialog.h
1 #ifndef DIALOG_H 2 #define DIALOG_H 3 4 #include <QDialog> 5 #include <QTextEdit> 6 #include <QComboBox> 7 #include <QLineEdit> 8 #include <QGridLayout> 9 #include <QPushButton> 10 11 namespace Ui { 12 class Dialog; 13 } 14 15 class Dialog : public QDialog 16 { 17 Q_OBJECT 18 19 public: 20 explicit Dialog(QWidget *parent = 0); 21 ~Dialog(); 22 23 private: 24 Ui::Dialog *ui; 25 QPushButton ***ppp; 26 }; 27 28 #endif // DIALOG_H
- dialog.cpp
1 #include "dialog.h" 2 #include "ui_dialog.h" 3 #include <QGridLayout> 4 5 Dialog::Dialog(QWidget *parent) : 6 QDialog(parent), 7 ui(new Ui::Dialog) 8 { 9 ui->setupUi(this); 10 11 QGridLayout *mainl = new QGridLayout(this); 12 13 ppp = new QPushButton** [5]; 14 15 for(int i=0;i<5;i++) 16 { 17 ppp[i] = new QPushButton*[4]; 18 for(int j=0;j<4;j++) 19 { 20 ppp[i][j] = new QPushButton(this); 21 ppp[i][j]->resize(50,50); 22 QString str; 23 str.sprintf("%d%d",i,j); 24 ppp[i][j]->setText(str); 25 mainl->addWidget(ppp[i][j],i,j); 26 } 27 } 28 } 29 30 Dialog::~Dialog() 31 { 32 delete ui; 33 }