Qt: QWidget,QDialog, 和 QMainwindow
Qt: QWidget,QDialog, 和 QMainwindow
QWidget
参考:Qt Help
Inherits: QObject and QPaintDevice
The QWidget class is the base class of all user interface objects.
A widget that is not embedded in a parent widget is called a window.
In Qt, QMainWindow and the various subclasses of QDialog are the most common window types.
Every widget’s constructor accepts one or two standard arguments:
- QWidget *parent = 0 is the parent of the new widget. If it is 0 (the default), the new widget will be a window. If not, it will be a child of parent, and be constrained by parent’s geometry (unless you specify Qt::Window as window flag).
- Qt::WindowFlags f = 0 (where available) sets the window flags; the default is suitable for almost all widgets, but to get, for example, a window without a window system frame, you must use special flags.
QDialog
Inherits: QWidget
The QDialog class is the base class of dialog windows.
A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user.
QDialogs may be modal or modeless.
modal dialog: A modal dialog is a dialog that blocks input to other visible windows in the same application.
modeless dialog: A modeless dialog is a dialog that operates independently of other windows in the same application.
QDialogs can provide a return value, and they can have default buttons.
return value (modal dialogs): Modal dialogs are often used in situations where a return value is required, e.g. to indicate whether the user pressed OK or Cancel.
The function returns a DialogCode result.
default buttons: A dialog’s default button is the button that’s pressed when the user presses Enter (Return).
Esc key: If the user presses the Esc key in a dialog, QDialog::reject() will be called. This will cause the window to close: The close event cannot be ignored.
QDialog (and any other widget that has type Qt::Dialog) uses the parent widget slightly differently from other classes in Qt ???
A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent’s top-level widget (if it is not top-level itself).
It will also share the parent’s taskbar entry.
QMainwindow
Inherits: QWidget
The QMainWindow class provides a main application window.
QMainWindow has its own layout to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar.
The layout has a center area that can be occupied by any kind of widget.