#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QtGui/QMainWindow>#include "dockwidget.h"namespace Ui{ class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow();private: Ui::MainWindow *ui; DockWidget widget; bool boolean;private slots: void on_pushButton_clicked();};#endif // MAINWINDOW_H
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); boolean = false;}MainWindow::~MainWindow(){ delete ui;}void MainWindow::on_pushButton_clicked(){ if (!boolean) { widget.show(); boolean = true; } else { widget.hide(); boolean = false; }}
#ifndef DOCKWIDGET_H#define DOCKWIDGET_H#include <QtGui/QDockWidget>namespace Ui{ class DockWidget;}class DockWidget : public QDockWidget { Q_OBJECTpublic: DockWidget(QWidget *parent = 0); ~DockWidget();private: Ui::DockWidget *m_ui;};#endif // DOCKWIDGET_H
#include "dockwidget.h"#include "ui_dockwidget.h"DockWidget::DockWidget(QWidget *parent) : QDockWidget(parent), m_ui(new Ui::DockWidget){ m_ui->setupUi(this);}DockWidget::~DockWidget(){ delete m_ui;}
C++ (Qt)private: Ui::MainWindow *ui; DockWidget* widget;
C++ (Qt)MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); widget = new DockWidget(this); widget->setVisible(false);} MainWindow::~MainWindow(){ delete ui;} void MainWindow::on_pushButton_clicked(){ widget->setVisible(!widget->isVisible());}