Main Window and related Classes
Qaction |
Action class for inserting a menu or toolbar as a menu item or tool item |
Qactiongroup |
Action groups for managing multiple actions, setting the mutex between them, etc. |
Qwidgetaction |
Part action, inherited from Qaction, for inserting widgets into menus or toolbars |
Qdockwidget |
Suspension parts, parts that can be dragged by the mouse after the program is run |
Qmainwindow |
Main window, which is a container for other parts |
Qmdiarea |
Sub-area, added to Qmainwindow, for placing multiple Qmdisubwindow child windows |
Qmdisubwindow |
child window |
Qmenu |
Menu |
Qmenubar |
menu bar with multiple menus |
Qsizegrip |
Manage top-level window size, usually in the lower right corner of the software, the right side of the status bar, the mouse can drag it to change the window size |
Qstatusbar |
Status bar |
Qtoolbar |
Tool bar |
The Qmainwindow, which forms the parts of the traditional interface, is now dragged together to record them.
In the case of RAR compression software interface, the components are as follows:
The top line, called the menu bar, consists of "file", "command" and other menus, "Options" menu has been clicked, pop up a lot of menu items, QT uses action class qaction to represent menu items. That is, qaction constitutes a menu, the menu forms a menu bar, qaction can add text, pictures, etc. to form a beautiful menu item. Qdockwidget Suspension parts are special, and when the program is running, drag to change its position.
——————————————————————————————————————————————————————————————————
Setup steps:
In order to build a traditional interface, you need to choose an inheriting class when you set up a project, such as.
After completion, the UI file is as follows, "Enter Here" is to ask us to create a menu, the bottom layer of the menu bar is the default toolbar, no added action, so very small (the left side has a small dot)
by double-clicking "Enter Here", you can write text, for example, by entering the "file" that you used to create it. At the bottom of the five buttons at the first new action, you can specify the name of the action, shortcut keys, etc., after the completion, drag it to the menu or toolbar.
The following are:
At this point, as soon as the "trigger" signal of this "action" is connected to a slot function, the slot function is executed by tapping on the menu item or "New" on the toolbar.
The above is the rough steps to build a traditional interface
——————————————————————————————————————————————————————————————
Qmainwindow
Each part of a main window is distributed
Contrast (the middle white large box in the picture is a qtablewidget table widget):
The public functions are categorized as follows:
Qmainwindow (qwidget * parent =0, Qt::windowflags flags =0) ~Qmainwindow ()//Settings Menu SectionvoidSetmenubar (Qmenubar * menuBar)//with the UI file by default there is a menu bar, if this is set, then the default is overwritten, a mainwindow can only have one main menu at the topvoidSetmenuwidget (Qwidget * menuBar)//Override the default menu, replace the menu with a custom part, or even use a button ..., more flexible than the default menu, you can try this. //Toolbar SectionvoidAddtoolbar (Qt::toolbararea area, Qtoolbar * toolbar)//add a toolbar with the enumeration value Qt::toolbararea (see 1) to set the docking area, visible from the graph, the docking area is divided into the upper and lower left and right four areas. voidAddtoolbar (Qtoolbar * toolbar)//add a toolbar (which is immediately followed by the previous tool bar)Qtoolbar * Addtoolbar (ConstQString &title)voidAddtoolbarbreak (Qt::toolbararea area = Qt::toptoolbararea)//Add a break (burst; breaks; or translate to a region), at which point the newly added toolbar will no longer follow the previous toolbar, but another line. voidInserttoolbar (Qtoolbar * before, Qtoolbar * toolbar)//after the Before toolbar, add avoidInserttoolbarbreak (Qtoolbar * before)//Add separator linesvoidRemovetoolbar (Qtoolbar *toolbar)voidRemovetoolbarbreak (Qtoolbar *before)voidSettoolbuttonstyle (Qt::toolbuttonstyle Toolbuttonstyle)//set the display mode on the toolbar, the default is only the file, can be set to picture or text form (see 2)voidSeticonsize (ConstQsize & Iconsize)//Sets the tool bar size, which is valid after the previous function set icon mode//dockable WidgetsvoidAdddockwidget (Qt::D ockwidgetarea area, Qdockwidget * dockwidget)//Area enumeration values See 3voidAdddockwidget (Qt::D ockwidgetarea area, Qdockwidget *Dockwidget, qt::orientation Orientation)voidRemovedockwidget (Qdockwidget *dockwidget)voidSetCorner (Qt::corner Corner, Qt::D ockwidgetarea area)//let the Four Corners (corner) in an area "belong to" an area, see the bottom of the examplevoidSetdockoptions (dockoptions options)//set docking options, such as allowing animations or whether to allow drag-and-drop to re-compose parts of the tab type, see enumeration values 4voidSettabposition (Qt::D ockwidgetareas areas, Qtabwidget::tabposition tabposition)//set the tab position to formvoidSettabshape (qtabwidget::tabshape tabshape)voidSetdocumentmode (BOOLenabled)voidSplitdockwidget (Qdockwidget * First, Qdockwidget * second, qt::orientation Orientation)//when the part is dragged to the same area, the default Coincident Forms tab, which, using this, separates them//set up an intermediate partvoidSetcentralwidget (Qwidget *widget) Qwidget* Centralwidget ()Const //Add status barvoidSetstatusbar (Qstatusbar *StatusBar)//Save window Shape InformationBOOLRestorestate (ConstQbytearray & State,intVersion =0) <p>qbytearray SaveState (intVersion =0)Const BOOLRestoredockwidget (Qdockwidget *dockwidget)</p>//otherQt::D ockwidgetarea Corner (Qt::corner corner)Const VirtualQmenu *CreatePopupMenu () dockoptions dockoptions ()ConstQt::D ockwidgetarea dockwidgetarea (qdockwidget* Dockwidget)Const BOOLDocumentmode ()Constqsize iconsize ()Const BOOLIsAnimated ()Const BOOLIsdocknestingenabled ()ConstQmenubar* MenuBar ()ConstQwidget* Menuwidget ()ConstQstatusbar* StatusBar ()Constqtabwidget::tabposition tabposition (Qt::D ockwidgetarea area)Constqtabwidget::tabshape tabshape ()Constqlist<qdockwidget *> tabifieddockwidgets (qdockwidget * dockwidget)Const voidTabifydockwidget (Qdockwidget * First, Qdockwidget *second) Qwidget*takecentralwidget () Qt::toolbararea Toolbararea (Qtoolbar* Toolbar)Const BOOLToolbarbreak (Qtoolbar * toolbar)ConstQt::toolbuttonstyle Toolbuttonstyle ()Const
1,enum Qt::toolbararea
Constant |
Value |
Qt::lefttoolbararea |
0x1 |
Qt::righttoolbararea |
0x2 |
Qt::toptoolbararea |
0x4 |
Qt::bottomtoolbararea |
0x8 |
Qt::alltoolbarareas |
Toolbararea_mask |
Qt::notoolbararea |
0
|
2,enum Qt::toolbuttonstyle
the text appears beside the icon.
constant |
value |
description |
qt::toolbuttonicononly |
0 |
show icons only |
Qt:: Toolbuttontextonly |
1 |
only display the text. |
qt::toolbuttontextbesideicon |
2 |
qt::toolbuttontextundericon |
3 |
text appears below the icon |
qt::toolbuttonfollowstyle |
4 |
follow The style. |
3,enum Qt::D ockwidgetarea
Flags Qt::D ockwidgetareas
Constant |
Value |
Qt::leftdockwidgetarea |
0x1 |
Qt::rightdockwidgetarea |
0x2 |
Qt::topdockwidgetarea |
0x4 |
Qt::bottomdockwidgetarea |
0x8 |
Qt::alldockwidgetareas |
Dockwidgetarea_mask |
Qt::nodockwidgetarea |
0 |
4,enum Qmainwindow::D ockoption
Flags Qmainwindow::D ockoptions
Constant |
Value |
Description |
Qmainwindow::animateddocks |
0x01 |
Same as animated |
Qmainwindow::allownesteddocks |
0x02 |
Same as Docknestingenabled |
Qmainwindow::allowtabbeddocks |
0x04 |
Allows to form coincident parts with Tapbar below |
Qmainwindow::forcetabbeddocks |
0x08 |
Each dock area contains a single stack of tabbed dock widgets. In the other words, dock widgets cannot is placed next to each other in a dock area. If This option was set, Allownesteddocks has no effect. |
Qmainwindow::verticaltabs |
0x10 |
Set Tabbar in vertical left position (default below) |
In the case of RAR compression software, the main parts of the interface are written in code:
The following code is only for understanding, is very unreasonable. Main test the location of each part of the widget, appearance, and Mainwidow shape configuration Save
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QAction> #include <QMenu> #include <qicon > #include <QSize> #include <QLabel> #include <QDockWidget> #include <QTableWidget> #include <qsettings>mainwindow::mainwindow (Qwidget *parent): Qmainwindow (parent), UI (new Ui::mainwindow) {Ui->se TUPUI (this); Menu bar Section Qmenu *menu1=ui->menubar->addmenu ("File (&f)"); Qaction *me1_act1=menu1->addaction ("Open compressed file (O)"); Me1_act1->setshortcut (qkeysequence (tr ("Ctrl+o")); Connect (me1_act1,signal (triggered)),...... Qaction *me1_act2=menu1->addaction ("Save copy of compressed file as (V)"); Me1_act2->seticon (Qicon ("://img/sava.ico")); Menu1->addseparator (); Qaction *me1_act3=menu1->addaction ("Exit (X)"); Connect (me1_act3,signal (triggered ()), This,slot (Close ())); Ui->menubar->addmenu ("command (&C)"); The "File" menu section qaction *tb1_act1=ui->maintoolbar->addaction (Qicon ("://img/tool1.ico"), "add"); Ui->maintOolbar->addseparator (); Qaction *tb1_act2=ui->maintoolbar->addaction (Qicon ("://img/tool2.ico"), "extract to"); Settoolbuttonstyle (Qt::toolbuttontextundericon); Seticonsize (Qsize (50,50)); Addtoolbarbreak (); Toolbar=new Qtoolbar; Toolbar->setobjectname ("TB2");//Set object name for saving configuration Toolbar->settoolbuttonstyle (qt::toolbuttonicononly); Toolbar->seticonsize (Qsize (20,20)); Addtoolbar (ToolBar); Qaction *tb2_act1=toolbar->addaction (Qicon ("://img/sharp.ico"), ""); Add Intermediate main part qtablewidget *tb1=new qtablewidget; Setcentralwidget (TB1); Add Suspension parts Qdockwidget *dock1= new Qdockwidget ("Upper side Parts"); Adddockwidget (QT::TOPDOCKWIDGETAREA,DOCK1); Qdockwidget *dock2_1= New Qdockwidget ("left Part 1"); Adddockwidget (Qt::leftdockwidgetarea,dock2_1); Qdockwidget *dock2_2= New Qdockwidget ("left Part 2"); Adddockwidget (qt::leftdockwidgetarea,dock2_2); Splitdockwidget (dock2_1,dock2_2,qt::horizontal); Qdockwidget *dock3= New Qdockwidget ("right part"); Dock3->setfeaTures (qdockwidget::D ockwidgetverticaltitlebar| Qdockwidget::D ockwidgetmovable); Adddockwidget (QT::RIGHTDOCKWIDGETAREA,DOCK3); Qdockwidget *dock4= New Qdockwidget ("Lower side part"); Adddockwidget (QT::BOTTOMDOCKWIDGETAREA,DOCK4); SetCorner (Qt::bottomleftcorner,qt::leftdockwidgetarea);//Let the lower left corner area be attributed to the left docking area dock1->setobjectname ("Dock1"); Dock2_1->setobjectname ("Dock2_1"); Dock2_2->setobjectname ("Dock2_2"); Dock3->setobjectname ("Dock3"); Dock4->setobjectname ("Dock4"); Status bar Section Qlabel *lbl1=new qlabel ("stateless"); Ui->statusbar->addwidget (LBL1); Read window and part shape and status readsettings ();} void Mainwindow::closeevent (Qcloseevent *event) {qsettings settings ("Greater China Limited", "Test software name"); Settings.setvalue ("Geometry", savegeometry ()); Settings.setvalue ("WindowState", SaveState ()); Settings.sync ();} void Mainwindow::readsettings () {qsettings settings ("Greater China Limited", "Test software name"); Restoregeometry (Settings.value ("geometry"). Tobytearray ()); Restorestate (Settings.value("WindowState"). Tobytearray ());} Mainwindow::~mainwindow () {Delete UI;}
Qt widgets--main window and its main components