When you create a project, you find that the editor provides three base classes, respectively:
Qmainwindow, Qwidget, Qdialog, the differences between the three base classes are described below.
1, Qmainwindow
the Qmainwindow class provides a main application with a menu bar, an anchor window (such as a toolbar), and a status bar
program window. The main window is typically used to provide a large central window widget (such as text editing or drawing canvas) and
surrounding menus, toolbars, and a status bar. Qmainwindow are often inherited, as this enables the encapsulation of central components,
The toolbar and the window status bar are made easier, and when the user taps the menu item or toolbar button, the slot is
use.
2, Qwidget
the Qwidgt class is the base class for all user-interface objects. A widget is a basic unit of the user interface: It is from the window
The port system receives the mouse, keyboard, and other events and draws itself on the screen. Each widget is rectangular,
and they are arranged in the z-axis order. A widget can be covered by its parent window part or by a widget in front of it
part.
3, Qdialog
the Qdialog class is the base class for dialog Windows. The dialog window is primarily used for short-term tasks as well as for brief user
the top-level window for communication. Qdialog can be modal dialogs or non-modal dialog boxes. Qdialog supports extensibility and
and can provide a return value. They can have default buttons.
Of course, you can also add a new base class object to the main function
int main (int argc, char *argv[]) { qapplication app (argc, argv); Qwidget*window=new Qwidget; Window->setwindowtitle ("Enter your Age"); Qspinbox *spinbox=new Qspinbox; Qslider *slider = new Qslider (qt::horizontal); Spinbox->setrange (0,130); Slider->setrange (0,130); Qobject::connect (Slider,signal (valuechanged (int)), Spinbox,slot (setValue (int))); Qobject::connect (Spinbox,signal (valuechanged (int)), Slider,slot (setValue (int))); Spinbox->setvalue (+); Qhboxlayout*layout=new qhboxlayout;//Horizontal Layout, the next four lines are placed //qhboxlayout-in horizontal direction from left to right layout; //qvboxlayout- From top to bottom in a vertical direction; //qgridlayout-is laid out in a grid, similar to the HTML table. Layout->addwidget (spinbox); Layout->addwidget (slider); Window->setlayout (layout); Window->show (); return app.exec ();}
Three major forms of QT5