16,766
社区成员




#ifndef MAINWINDOW_H
//mainwindow.h
#define MAINWINDOW_H
#include <QMainWindow>
class QMdiArea;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QMdiArea *mdiArea;
};
#endif // MAINWINDOW_H
//mainwindow.cpp
#include "mainwindow.h"
#include "subwidget.h"
#include <QMdiArea>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
this->setWindowState(Qt::WindowMaximized);//窗体以最大化显示
SubWidget *form = new SubWidget(this);
mdiArea->addSubWindow(form,Qt::Dialog | Qt::WindowMinimizeButtonHint);
}
MainWindow::~MainWindow()
{
}
//subwidget.h
#ifndef SUBWIDGET_H
#define SUBWIDGET_H
#include <QWidget>
class SubWidget : public QWidget
{
Q_OBJECT
public:
explicit SubWidget(QWidget *parent = 0);
signals:
public slots:
};
#endif // SUBWIDGET_H
//subwidget.cpp
#include "subwidget.h"
SubWidget::SubWidget(QWidget *parent) :
QWidget(parent)
{
this->setFixedSize(200,200);
this->setStyleSheet(QString::fromUtf8("background-color: rgb(195, 0, 255);"));
}
//main.cpp
#include <QApplication>
#include <QDialog>
#include "mainwindow.h"
#include "subwidget.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
MainWindow w;
w.show();
/*直接作为主窗体显示就没有问题
SubWidget subWidget;
subWidget.show();
*/
return app.exec();
}
//test.pro
FORMS +=
SOURCES += \
main.cpp \
mainwindow.cpp \
subwidget.cpp
HEADERS += \
mainwindow.h \
subwidget.h