Qmdiarea is typically used for the main window Qmainwindow to hold multiple child windows Qmdisubwindow
QT Creator 3.0 designers have mdiarea that can be dragged directly into use.
The interface is as follows, the gray box in the figure is a mdiarea, and the other one creates 2 Qmdisubwindow: The code is as follows:
#include"mainwindow.h"#include"ui_mainwindow.h"#include<QSize>Mainwindow::mainwindow (Qwidget*parent): Qmainwindow (parent), UI (NewUi::mainwindow) {UI->SETUPUI ( This); Connect (UI->actionnew,signal (triggered ()), This, SLOT (Creatnewwin ()));//Actionnew is an action created by a designer } voidMainwindow::creatnewwin () {mdiWin1=NewQmdisubwindow; MdiWin1->setwindowtitle ("Undecided"); UI->mdiarea->Addsubwindow (mdiWin1); MdiWin1->resize (Qsize ( $, $)); MdiWin1-Show (); } MainWindow::~MainWindow () {Delete UI; }
______________________________________________________________________________________________
Qmdiarea public functions are as follows:
Qmdiarea (qwidget * parent =0) ~Qmdiarea () Qmdisubwindow* Addsubwindow (Qwidget * widget, qt::windowflags windowflags =0) voidRemovesubwindow (Qwidget *widget)voidSetactivationorder (Windoworder order)//set the activation order by default to create a sequential activation, the slot function has a call, the enumeration value is shown in 1voidSetBackground (ConstQbrush & Background)//set background, default grayvoidSetdocumentmode (BOOLenabled)voidSetOption (areaoption option,BOOLOn =true)//now there is only one option, that is to create a subwindow, the window is not filled with this area, the default is full, enumeration values are shown in 2voidSetviewmode (ViewMode mode)//Set viewport mode, the default area of a lot of small windows, can also be Tabbar form, the following these Settings tab function, you need to first open this. Enumeration values are shown in 3voidSettabposition (qtabwidget::tabposition position)//set the azimuth of the Tabbar, have the East four directions, follow the geographical upper North lower left West right East enumeration value See 4voidSettabshape (Qtabwidget::tabshape shape)//set tab shape, default rectangle, can also be like Google Chrome, trapezoid, enumeration value See 5voidSettabsclosable (BOOLclosable)//default No, when set to true, a close small button is formed above the tabvoidSettabsmovable (BOOLMovable)//whether the settings can be moved, by default false, can be moved, you can drag tab to move on the Tabbar, now the browser mostly has this functionqlist<qmdisubwindow *> subwindowlist (windoworder order = creationorder)ConstQmdisubwindow* Currentsubwindow ()Constwindoworder Activationorder ()ConstQbrush background ()Const BOOLDocumentmode ()Const BOOLTestoption (areaoption option)ConstQmdisubwindow* Activesubwindow ()Constqtabwidget::tabposition tabposition ()Constqtabwidget::tabshape tabshape ()Const BOOLTabsclosable ()Const BOOLTabsmovable ()ConstViewMode ViewMode ()Const
Public Slots
void Activatenextsubwindow () void activateprevioussubwindow () void cascadesubwindows () void closeactivesubwindow () void closeallsubwindows () void Setactivesubwindow (Qmdisubwindow * window) void Tilesubwindows ()// arranges all child windows neatly in the visible part of area
Signals
void subwindowactivated (Qmdisubwindow * window)// Toggle active window
1,enum Qmdiarea::windoworder
| Constant |
Value |
Description |
| Qmdiarea::creationorder |
0 |
By the order in which they were created |
| Qmdiarea::stackingorder |
1 |
Stacking order |
| Qmdiarea::activationhistoryorder |
2 |
Press to activate history before and after order. |
2,enum qmdiarea::areaoption
Flags Qmdiarea::areaoptions
| Constant |
Value |
Description |
| Qmdiarea::D ontmaximizesubwindowonactivation |
0x1 |
does not maximize when activated, it is maximized by default |
3,qmdiarea::viewmode
| Constant |
Value |
Description |
| Qmdiarea::subwindowview |
0 |
Display as a small window (default). |
| Qmdiarea::tabbedview |
1 |
Not only can small windows, but also form Tabbar |
4,enum qtabwidget::tabposition
| Constant |
Value |
Description |
| Qtabwidget::north |
0 |
Above display |
| Qtabwidget::south |
1 |
Under |
| Qtabwidget::west |
2 |
Left |
| Qtabwidget::east |
3 |
Right |
5,enum Qtabwidget::tabshape
| Constant |
Value |
Description |
| qtabwidget::rounded |
0 |
is literally round, but Win7 more like a rectangle, default |
| Qtabwidget::triangular |
1 |
Literal triangle that says it's trapezoid better |
In the above code, the result of executing the tilesubwindows () function is shown in the figure:
#include"mainwindow.h"#include"ui_mainwindow.h"#include<QSize>#include<QTabWidget>#include<QBrush>Mainwindow::mainwindow (Qwidget*parent): Qmainwindow (parent), UI (NewUi::mainwindow) {UI->SETUPUI ( This); Qbrush b=qbrush (Qcolor ( -, -, -), Qt::fdiagpattern); UI->mdiarea->SetBackground (b); UI->mdiarea->Setviewmode (Qmdiarea::tabbedview); UI->mdiarea->settabposition (Qtabwidget::north); UI->mdiarea->settabsclosable (true); UI->mdiarea->settabsmovable (true); UI->mdiarea->Settabshape (qtabwidget::triangular); UI->mdiarea->setOption (qmdiarea::D ontmaximizesubwindowonactivation); Connect (UI->actionnew,signal (triggered ()), This, SLOT (Creatnewwin ())); } voidMainwindow::creatnewwin () {mdiWin1=NewQmdisubwindow; MdiWin1->setwindowtitle ("Undecided"); UI->mdiarea->Addsubwindow (mdiWin1); MdiWin1->resize (Qsize ( $, $)); MdiWin1-Show (); } MainWindow::~MainWindow () {Delete UI; } voidmainwindow::on_pushbutton_clicked () {UI->mdiarea->tilesubwindows (); }
______________________________________________________________________________________________
The Qmdisubwindow functions are relatively simple and are listed as follows:
Qmdisubwindow (qwidget * parent =0, Qt::windowflags flags =0) ~Qmdisubwindow ()voidSetkeyboardpagestep (intStep)voidSetkeyboardsinglestep (intStep)voidSetOption (subwindowoption option,BOOLOn =true)//trial effect, supplementary, enumeration values see 1voidSetsystemmenu (Qmenu *systemmenu). SE. voidSetwidget (Qwidget * widget)//to add its widgets primarily through a function intKeyboardpagestep ()Const intKeyboardsinglestep ()ConstQmdiarea* Mdiarea ()ConstQmenu* Systemmenu ()ConstQwidget* Widgets ()Const BOOLTestoption (subwindowoption option)Const BOOLIsshaded ()Const
Public Slots
| void |
Showshaded () |
| void |
Showsystemmenu () |
Signals
| void |
Abouttoactivate () |
| void |
Windowstatechanged (qt::windowstates oldstate, qt::windowstates newstate) |
1,enum qmdisubwindow::subwindowoption
| Constant |
Value |
Description |
| qmdisubwindow::rubberbandresize |
0x4 | TD class= "Topalign" >if you enable this option, a rubber band control are used to represent the Subwindow ' s outline, and the User resizes this instead of the subwindow itself. As a result, the Subwindow maintains its original position and size until the resize operation have been completed, at whic H time it would receive a single qresizeevent. By default, this option is disabled.
| Qmdisubwindow::rubberbandmove |
0x8 |
If you enable this option, a rubber band control was used to represent the Subwindow ' s outline, and the user moves this ins Tead of the subwindow itself. As a result, the Subwindow remains in its original position until the move operation have completed, at which time Aqmoveev ENT is sent to the window. By default, this option is disabled.
|
Qt widgets--Sub-regions and child windows