Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main:
- #include "base.h"
- #include <QApplication>
- #include <QLabel>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Base w;
- w.show();
- return a.exec();
- }
- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
- Base.h
- #ifndef BASE_H
- #define BASE_H
- #include <QPushButton>
- #include <QMainWindow>
- #include <QVBoxLayout>
- class Base : public QWidget
- {
- Q_OBJECT
- public:
- explicit Base(QWidget *parent = 0);
- ~Base();
- public slots:
- void AddWidget();
- private:
- QVBoxLayout *Vlayout;
- };
- #endif
- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
- Base.cpp
- #include "base.h"
- #include <QApplication>
- #include <QPushButton>
- #include <QLabel>
- #include <QLayout>
- #include <QDialog>
- #include <QHBoxLayout>
- Base::Base(QWidget *parent)
- : QWidget(parent)
- {
- QHBoxLayout* Hlayout=new QHBoxLayout(this);
- Vlayout=new QVBoxLayout(this);
- QPushButton *m=new QPushButton("exit",this);
- QPushButton *l=new QPushButton("+",this);
- Hlayout->addWidget(l);
- Hlayout->addWidget(m);
- Vlayout->addLayout(Hlayout);
- connect(l,SIGNAL(clicked()),this,SLOT(AddWidget()));
- connect(m,SIGNAL(clicked()),qApp,SLOT(quit()));
- m->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
- l->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
- }
- Base::~Base()
- {}
- void Base::AddWidget(){
- Vlayout->addWidget(new QLabel("Added",this));
- Vlayout->update();
- /*QDialog *dialog= new QDialog(this);
- QVBoxLayout *t= new QVBoxLayout(dialog);
- t->addWidget(new QLabel("QLabel added successfully",dialog));
- dialog->show();*/
- }
Add Comment
Please, Sign In to add comment