QT Development (22)--qmainwindow main window
I. Introduction of the main window
The main window in the application is a top-level window that interacts with the user for a long time, providing most of the functionality of the application, usually the first window after the application is launched, which typically consists of a main window and multiple dialog boxes.
QT directly supports the main window, Qmainwindow is the base class for the main window in Qt, and is a container-type component that inherits from the Qwidget class.
The Qmainwindow interior encapsulates the menu bar, toolbars, central components, docking components, status bars, and more.
Qmainwindow has a layout manager built in, and the basic component layout is as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8A/12/wKioL1glpd_zMhFjAAAwa6zVz9o174.png "title=" Picture 8.png "alt=" Wkiol1glpd_zmhfjaaawa6zvz9o174.png "/>
Second, the menu bar
QT provides predefined menu-related class components, menu bar qmenubar, drop-down menu Qmenu and menu item qaction.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/8A/16/wKiom1glpf6glCWaAACpyc1o3iY491.png "title=" Picture 9.png "alt=" Wkiom1glpf6glcwaaacpyc1o3iy491.png "/>
qmenubar* MB = MenuBar ();
qmenu* menu = new Qmenu ("File (&f)");
Qaction *action = new Qaction (text, NULL);
Menu->addaction (action);
Mb->addmenu (menu);
Shortcut key Settings
Action->setshortcut (Qkeysequence (KEY));
Qkeysequence is a class in Qt that is related to shortcut keys, which are constants that represent key values in QT.
Third,
Tool Bar
Toolbars are areas in the application that integrate various features using shortcuts, not components that the application must exist, and the elements of the toolbar can be various window components, but usually exist as icon buttons.
QT provides predefined toolbar-related components, toolbar Qtoolbar, and shortcut item qaction.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/16/wKiom1glph3SczzfAACF2kKVHlg863.png "title=" Picture 10.png "alt=" Wkiom1glph3sczzfaacf2kkvhlg863.png "/>
1. How to use the toolbar
Creating toolbars
Qtoolbar *TB = Addtoolbar ("ToolBar");
To create a toolbar option
qaction * action = new Qaction ("", NULL);
Action->settooltip ("Open");
Action->seticon (Qicon ("/res/pic/open.png"));
add toolbar options to Toolbars
Tb->addaction (action);
2.qtoolbar utility function
void setfloatable (bool floatable) set the toolbar to float
void setmovable (bool movable) sets the toolbar to be movable
void seticonsize (const qsize & iconsize) Set the icon size of the toolbar
3. Toolbar Instances
Any qwidget component in QT can be added to the Qtollbar component.
qtoolbar* tb = Addtoolbar ("Tool Bar");
qaction* action = new Qaction ("", NULL);
Tb->setfloatable (FALSE);
Tb->setmovable (FALSE);
Action->settooltip ("Open");
Action->seticon (Qicon (":/res/open.png"));
Tb->addaction (action);
qpushbutton* B = new Qpushbutton ("button");
qlabel* L = new Qlabel ("Label");
qlineedit* e = new Qlineedit ();
Tb->addwidget (b);
Tb->addwidget (l);
Tb->addwidget (e) ;
iv. status Bar
The status bar is the area in the application where you output summary information, usually at the bottom of the window. The status bar displays the following message types:
A, real-time messages, such as the current program status
B, permanent messages, such as program versions, development agencies
C, progress message, progress display
The predefined status bar-related component status bar is provided in Qt Qstatusbar,qstatusbar is a container-type component and can be the parent component of any component Qwidget.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8A/16/wKiom1glpj7RdsgYAABSeazyFAg766.png "title=" Picture 11.png "alt=" Wkiom1glpj7rdsgyaabseazyfag766.png "/>
General design principles for the QT status bar:
A, the left area of the status bar is used to output real-time messages
B. The right area of the status bar is used to output a permanent message
Therefore,the AddWidget function is used to add components to the left area of the status bar, and the Addpermanentwidget function is used to add components to the right area of the status bar.
The status bar uses the following methods:
qstatusbar* sb = StatusBar ();
qlabel* label = new Qlabel ("CopyRight @ Scorpio Studio 2016");
if (label! = NULL)
{
Line.setminimumwidth (120);
Line.setalignment (Qt::aligncenter);
Line.settext ("Ln:1 col:1");
Label->setminimumwidth (160);
Label->setalignment (Qt::aligncenter);
Sb->addpermanentwidget (New Qlabel ());
Sb->addpermanentwidget (&line);
Sb->addpermanentwidget (label);
}
Five,
Text editing Components
Three types of text editing components are pre-defined in QT to meet different development needs.
A, Qlineedit Single-line text editing component
B, Qtextedit Multi-line Rich text editing component
C, Qplaintextedit Multi-line Plain text editing component
Class inheritance diagram for qt text editing components:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/12/wKioL1glpl-i5t0pAAB15EH9KoY622.png "title=" Picture 12.png "alt=" Wkiol1glpl-i5t0paab15eh9koy622.png "/>
The text editing component in Qt has a right-click Popup and shortcut key function.
Use of the text editor:
To set the parent component of a text editor
maineditor.setparent (this);
set the text editor as a central component
Setcentralwidget (&maineditor);
This article from "Life is endless, struggle not only" blog, declined reprint!
QT Development (22)--qmainwindow main window