#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QWidget>#include <QPushButton>#include <QVBoxLayout>class MainWindow : public QWidget{ Q_OBJECT public: MainWindow(QWidget *parent = 0);private: int count;public slots: void addButton();};#endif // MAINWINDOW_H
#include "mainwindow.h"/// PUBLICMainWindow::MainWindow(QWidget *parent): QWidget(parent), count(0){ QPushButton *pButtonAddButton = new QPushButton("Click ME!!!"); connect(pButtonAddButton, SIGNAL(clicked()), this, SLOT(addButton())); QVBoxLayout *vBoxLayoutMain = new QVBoxLayout(); vBoxLayoutMain->addWidget(pButtonAddButton); setLayout(vBoxLayoutMain);}/// PUBLIC SLOTSvoid MainWindow::addButton(){ count++; QPushButton *pButtonNew = new QPushButton(QString::number(count)); connect(pButtonNew, SIGNAL(clicked()), this, SLOT(addButton())); this->layout()->addWidget(pButtonNew);}
void SBranchPointMenu::addPoint(){ QPushButton *pButtonNew = new QPushButton("a!"); QVBoxLayout *vBoxLayoutMain = new QVBoxLayout(qobject_cast<QWidget*>(point->parent())); vBoxLayoutMain->addWidget(pButtonNew);}