1、常用功能函数
Qt全屏显示函数 window.showFullScreen()
Qt最大化显示函数 window.showMaximized()
Qt最小化显示函数 window.showMinimized()
Qt固定尺寸显示函数 window.resize(x,y)
void MainWindow::on_action_21_triggered() { HelpWnd *hw=new HelpWnd(this); if(!ui->mdiArea->subWindowList().isEmpty()) { ui->mdiArea->closeAllSubWindows(); } QMdiSubWindow *subWindow = ui->mdiArea->addSubWindow(hw,0); subWindow->setWindowTitle(tr("帮助文档")); subWindow->showMaximized(); }
前者是平铺方式设置背景,后者是拉伸方式设置背景
3、遍历QMdiSubWindowlist里的窗口,当新建窗口时可以保证实例的唯一性,用子窗口的windowtitle作为判断标志。
void MainWindow::on_action_21_triggered() { bool flags=false; if(ui->mdiArea->subWindowList().isEmpty()) { HelpWnd *hw = new HelpWnd(this); QMdiSubWindow *subWindow = ui->mdiArea->addSubWindow(hw,0); subWindow->setWindowTitle(tr("帮助文档")); subWindow->showMaximized(); } else { for(int i=0;i<ui->mdiArea->subWindowList().size();i++) { if(tr("帮助文档")==ui->mdiArea->subWindowList().at(i)->windowTitle()) { ui->mdiArea->subWindowList().at(i)->showMaximized(); flags=true; } } if(flags==false) { HelpWnd *hw = new HelpWnd(this); QMdiSubWindow *subWindow = ui->mdiArea->addSubWindow(hw,0); subWindow->setWindowTitle(tr("帮助文档")); subWindow->showMaximized(); } } }
4、在一个QMainWindow中建立一个QMdiArea的例子
VS中建立一个QMainWindow项目,通过ui会自动生成一段代码ui_xxx.h,我们以后就可以使用多文档界面了。
/******************************************************************************** ** Form generated from reading UI file 'MainWindow.ui' ** ** Created: Thu Feb 16 19:10:50 2012 ** by: Qt User Interface Compiler version 4.7.4 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_MAINWINDOW_H #define UI_MAINWINDOW_H #include <QtCore/QVariant> #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QButtonGroup> #include <QtGui/QHeaderView> #include <QtGui/QMainWindow> #include <QtGui/QMdiArea> #include <QtGui/QMenuBar> #include <QtGui/QStatusBar> #include <QtGui/QToolBar> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE class Ui_MainWindowClass { public: QWidget *centralWidget; QMdiArea *mdiArea; QMenuBar *menuBar; QToolBar *mainToolBar; QStatusBar *statusBar; void setupUi(QMainWindow *MainWindowClass) { if (MainWindowClass->objectName().isEmpty()) MainWindowClass->setObjectName(QString::fromUtf8("MainWindowClass")); MainWindowClass->resize(761, 593); MainWindowClass->setMinimumSize(QSize(0, 0)); centralWidget = new QWidget(MainWindowClass); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); mdiArea = new QMdiArea(centralWidget); mdiArea->setObjectName(QString::fromUtf8("mdiArea")); mdiArea->setGeometry(QRect(30, 40, 560, 350)); MainWindowClass->setCentralWidget(centralWidget); menuBar = new QMenuBar(MainWindowClass); menuBar->setObjectName(QString::fromUtf8("menuBar")); menuBar->setGeometry(QRect(0, 0, 761, 23)); MainWindowClass->setMenuBar(menuBar); mainToolBar = new QToolBar(MainWindowClass); mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); MainWindowClass->addToolBar(Qt::TopToolBarArea, mainToolBar); statusBar = new QStatusBar(MainWindowClass); statusBar->setObjectName(QString::fromUtf8("statusBar")); MainWindowClass->setStatusBar(statusBar); retranslateUi(MainWindowClass); QMetaObject::connectSlotsByName(MainWindowClass); } // setupUi void retranslateUi(QMainWindow *MainWindowClass) { MainWindowClass->setWindowTitle(QApplication::translate("MainWindowClass", "PET/CT\346\216\247\345\210\266\345\217\260", 0, QApplication::UnicodeUTF8)); } // retranslateUi }; namespace Ui { class MainWindowClass: public Ui_MainWindowClass {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_MAINWINDOW_H