Guest User

Untitled

a guest
May 5th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. Main:
  3.  
  4. #include "base.h"
  5. #include <QApplication>
  6. #include <QLabel>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. QApplication a(argc, argv);
  11. Base w;
  12. w.show();
  13. return a.exec();
  14. }
  15.  
  16. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
  17.  
  18. Base.h
  19.  
  20. #ifndef BASE_H
  21. #define BASE_H
  22. #include <QPushButton>
  23. #include <QMainWindow>
  24. #include <QVBoxLayout>
  25.  
  26. class Base : public QWidget
  27. {
  28. Q_OBJECT
  29.  
  30. public:
  31. explicit Base(QWidget *parent = 0);
  32. ~Base();
  33.  
  34. public slots:
  35. void AddWidget();
  36.  
  37. private:
  38. QVBoxLayout *Vlayout;
  39. };
  40.  
  41. #endif
  42.  
  43. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
  44.  
  45. Base.cpp
  46.  
  47. #include "base.h"
  48. #include <QApplication>
  49. #include <QPushButton>
  50. #include <QLabel>
  51. #include <QLayout>
  52. #include <QDialog>
  53. #include <QHBoxLayout>
  54.  
  55. Base::Base(QWidget *parent)
  56. : QWidget(parent)
  57. {
  58. QHBoxLayout* Hlayout=new QHBoxLayout(this);
  59. Vlayout=new QVBoxLayout(this);
  60.  
  61. QPushButton *m=new QPushButton("exit",this);
  62. QPushButton *l=new QPushButton("+",this);
  63.  
  64. Hlayout->addWidget(l);
  65. Hlayout->addWidget(m);
  66.  
  67. Vlayout->addLayout(Hlayout);
  68.  
  69. connect(l,SIGNAL(clicked()),this,SLOT(AddWidget()));
  70. connect(m,SIGNAL(clicked()),qApp,SLOT(quit()));
  71.  
  72. m->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  73. l->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  74. }
  75.  
  76. Base::~Base()
  77. {}
  78.  
  79. void Base::AddWidget(){
  80.  
  81. Vlayout->addWidget(new QLabel("Added",this));
  82. Vlayout->update();
  83.  
  84. /*QDialog *dialog= new QDialog(this);
  85. QVBoxLayout *t= new QVBoxLayout(dialog);
  86. t->addWidget(new QLabel("QLabel added successfully",dialog));
  87. dialog->show();*/
  88. }
Add Comment
Please, Sign In to add comment