写这个的原因,不是简单的抄文档(书到用时方恨少,懒驴上磨屎尿多)
1.上下班可以翻出博客看看
2.算是qt入门对 dialog widget mianwindow有大体上的认识。将创建项目时的选项做一个区别认识
3.最主要英文不好,直接看文档看不懂。翻译出的中文也不全对。放在博客里对比着看
目录
QWidget
mainwindow
dialog
1 基本小部件类
2. Advanced Widget Classes
3.Abstract Widget Classes
4.Organizer Widget Classes
5.Graphics View Classes
6.Model/View Classes
7.Main Window and Related Classes
8.Widget Appearance and Style-Related Classes
9.Layout Classes
QWidget类是所有用户界面对象的基类。 窗口部件是用户界面的一个基本单元:它从窗口系统接收鼠标、键盘和其它事件,并且在屏幕上绘制自己。每一个窗口部件都是矩形的,并且它们按Z轴顺序排列。一个窗口部件可以被它的父窗口部件或者它前面的窗口部件盖住一部分。
Widget是在Qt中创建用户界面的主要元素。Widget可以显示数据和状态信息,接收用户输入,并为应分组在一起的其他Widget提供容器。未嵌入父窗口Widget中的窗口Widget称为窗口。QWidget类提供了呈现到屏幕以及处理用户输入事件的基本功能。 Qt提供的所有UI元素要么是QWidget的子类,要么与QWidget子类结合使用。通过自定义QWidget或合适的子类并重新实现虚拟事件处理程序,可以创建自定义窗口Widget。
下面mainwindow 与dialog都是 widget的子类
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Main Window and Related Classes mainwindow
Detailed Description
The QMainWindow class provides a main application window.
Qt Main Window Framework
A main window provides a framework for building an application's user interface. Qt has QMainWindow and its related classes for main window management. 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. You can see an image of the layout below.
主窗口提供了用于构建应用程序用户界面的框架。 Qt具有用于主窗口管理的QMainWindow及其相关类。 QMainWindow具有其自己的布局,您可以在其中添加QToolBars,QDockWidgets,QMenuBar和QStatusBar。布局具有可被任何类型的小部件占据的中心区域。您可以在下面看到布局的图像。
Note: Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.
Creating Main Window Components
A central widget will typically be a standard Qt widget such as a QTextEdit or a QGraphicsView. Custom widgets can also be used for advanced applications. You set the central widget with setCentralWidget().
Main windows have either a single (SDI) or multiple (MDI) document interface. You create MDI applications in Qt by using a QMdiArea as the central widget.
We will now examine each of the other widgets that can be added to a main window. We give examples on how to create and add them.
窗口和对话框小部件
未嵌入父窗口小部件中的窗口小部件称为窗口。 (通常,窗口具有框架和标题栏,尽管也可以使用适当的窗口标记来创建没有这种修饰的窗口)。在Qt中,QMainWindow和QDialog的各种子类是最常见的窗口类型。
在应用程序中,窗口提供了用于构建用户界面的屏幕空间。 Windows在视觉上将应用程序彼此分开,通常提供一种窗口装饰,使用户可以根据自己的喜好调整应用程序的大小和位置。 Windows通常集成到桌面环境中,并在某种程度上由桌面环境提供的窗口管理系统进行管理。例如,应用程序的选定窗口显示在任务栏中。
主窗口提供了用于构建应用程序用户界面的框架。 Qt具有用于主窗口管理的QMainWindow及其相关类。 QMainWindow具有其自己的布局,您可以在其中添加QToolBars,QDockWidgets,QMenuBar和QStatusBar。布局具有可被任何类型的小部件占据的中心区域。您可以在下面看到布局的图像。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Abstract Widget Classes dialog
详细说明
QDialog类是对话框窗口的基类。
对话窗口是顶级窗口,主要用于短期任务和与用户的简短通信。 QDialogs可以是模式对话框或无模式对话框。 QDialogs可以提供返回值,并且可以具有默认按钮。 QDialog也可以使用setSizeGripEnabled()在右下角具有QSizeGrip。
请注意,QDialog(以及其他所有类型为Qt :: Dialog的小部件)使用的父小部件与Qt中的其他类略有不同。对话框始终是顶级窗口小部件,但是如果对话框具有父级窗口小部件,则其默认位置位于父级顶级窗口小部件的顶部(如果它本身不是顶级窗口级)。它还将共享父级的任务栏条目。
使用QWidget :: setParent()函数的重载来更改QDialog小部件的所有权。此功能使您可以显式设置父级窗口小部件的窗口标志。使用重载的功能将清除指定窗口小部件的窗口系统属性的窗口标志(特别是它将重置Qt :: Dialog标志)。
Detailed Description
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. QDialogs can provide a return value, and they can have default buttons. QDialogs can also have a QSizeGrip in their lower-right corner, using setSizeGripEnabled ().
Note that 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.
Use the overload of the QWidget :: setParent () function to change the ownership of a QDialog widget. This function allows you to explicitly set the window flags of the reparented widget; using the overloaded function will clear the window flags specifying the window-system properties for the widget (in particular it will reset the Qt :: Dialog flag).
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
模态对话框
模态对话框是一种对话框,它阻止输入到同一应用程序中其他可见窗口。用于向用户请求文件名或用于设置应用程序首选项的对话框通常是模式对话框。对话框可以是应用程序模式(默认)或窗口模式。
当打开应用程序模式对话框时,用户必须完成与对话框的交互并关闭它,然后才能访问应用程序中的任何其他窗口。窗口模式对话框仅阻止访问与该对话框关联的窗口,从而允许用户继续使用应用程序中的其他窗口。
显示模式对话框的最常见方法是调用其exec()函数。当用户关闭对话框时,exec()将提供有用的返回值。通常,要关闭对话框并返回适当的值,我们将一个默认按钮(例如,OK)连接到accept()插槽,将一个Cancel按钮连接到reject()插槽。或者,您可以使用“已接受”或“已拒绝”来调用完成()插槽。
另一种方法是调用setModal(true)或setWindowModality(),然后显示()。与exec()不同,show()立即将控制权返回给调用者。调用setModal(true)对于进度对话框特别有用,在该对话框中,用户必须具有与对话框进行交互的能力,例如取消长时间运行的操作。如果同时使用show()和setModal(true)来执行较长的操作,则在处理期间必须定期调用QApplication :: processEvents(),以使用户能够与对话框进行交互。 (请参阅QProgressDialog。)
Modal Dialogs
A modal dialog is a dialog that blocks input to other visible windows in the same application. Dialogs that are used to request a file name from the user or that are used to set application preferences are usually modal. Dialogs can be application modal (the default ) or window modal.
When an application modal dialog is opened, the user must finish interacting with the dialog and close it before they can access any other window in the application. Window modal dialogs only block access to the window associated with the dialog, allowing the user to continue to use other windows in an application.
The most common way to display a modal dialog is to call its exec () function. When the user closes the dialog, exec () will provide a useful return value. Typically, to get the dialog to close and return the appropriate value, we connect a default button, eg OK, to the accept () slot and a Cancel button to the reject () slot. Alternatively you can call the done () slot with Accepted or Rejected.
An alternative is to call setModal (true) or setWindowModality (), then show (). Unlike exec (), show () returns control to the caller immediately. Calling setModal (true) is especially useful for progress dialogs, where the user must have the ability to interact with the dialog, eg to cancel a long running operation. If you use show () and setModal (true) together to perform a long operation, you must call QApplication :: processEvents () periodically during processing to enable the user to interact with the dialog. (See QProgressDialog.)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
无模式对话框
无模式对话框是独立于同一应用程序中其他窗口运行的对话框。在文字处理器中查找和替换对话框通常是无模式的,以允许用户与应用程序的主窗口和对话框进行交互。
使用show()显示无模式对话框,该控件立即将控制权返回给调用者。
如果您在隐藏对话框后调用show()函数,该对话框将以其原始位置显示。这是因为窗口管理器决定了程序员未明确放置的窗口的位置。要保留用户已移动的对话框的位置,请将其位置保存在closeEvent()处理程序中,然后将对话框移至该位置,然后再次显示它。
Modeless Dialogs
A modeless dialog is a dialog that operates independently of other windows in the same application. Find and replace dialogs in word-processors are often modeless to allow the user to interact with both the application's main window and with the dialog.
Modeless dialogs are displayed using show (), which returns control to the caller immediately.
If you invoke the show () function after hiding a dialog, the dialog will be displayed in its original position. This is because the window manager decides the position for windows that have not been explicitly placed by the programmer. To preserve the position of a dialog that has been moved by the user, save its position in your closeEvent () handler and then move the dialog to that position, before showing it again.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
QWidget部件模块提供了一组UI元素,用于创建经典的桌面样式用户界面。有关使用Widget的更多信息,请参见用户界面概述。
窗口小部件类
以下各节列出了小部件类。 有关一些示例,请参见Qt Widget Gallery(以后再写,本篇不做介绍)。
这些基本小部件(控件),例如 按钮,组合框和滚动条设计为直接使用。
QWidget |
The base class of all user interface objects |
QCheckBox |
Checkbox with a text label |
QComboBox |
Combined button and popup list |
QCommandLinkButton |
Vista style command link button |
QDateEdit |
Widget for editing dates based on the QDateTimeEdit widget |
QDateTimeEdit |
Widget for editing dates and times |
QTimeEdit |
Widget for editing times based on the QDateTimeEdit widget |
QDial |
Rounded range control (like a speedometer or potentiometer) |
QFocusFrame |
Focus frame which can be outside of a widget's normal paintable area |
QFontComboBox |
Combobox that lets the user select a font family |
QLabel |
Text or image display |
QLCDNumber |
Displays a number with LCD-like digits |
QLineEdit |
One-line text editor |
QMenu |
Menu widget for use in menu bars, context menus, and other popup menus |
QProgressBar |
Horizontal or vertical progress bar |
QPushButton |
Command button |
QRadioButton |
Radio button with a text label |
QScrollArea |
Scrolling view onto another widget |
QScrollBar |
Vertical or horizontal scroll bar |
QSizeGrip |
Resize handle for resizing top-level windows |
QSlider |
Vertical or horizontal slider |
QDoubleSpinBox |
Spin box widget that takes doubles |
QSpinBox |
Spin box widget |
QTabBar |
Tab bar, e.g. for use in tabbed dialogs |
QTabWidget |
Stack of tabbed widgets |
QToolBox |
Column of tabbed widget items |
QToolButton |
Quick-access button to commands or options, usually used inside a QToolBar |
QColumnView |
Model/view implementation of a column view |
QDataWidgetMapper |
Mapping between a section of a data model to widgets |
QListView |
List or icon view onto a model |
QTableView |
Default model/view implementation of a table view |
QTreeView |
Default model/view implementation of a tree view |
QDesktopWidget |
Access to screen information on multi-head systems |
QUndoView |
Displays the contents of a QUndoStack |
QCalendarWidget |
Monthly based calendar widget allowing the user to select a date |
QMacCocoaViewContainer |
Widget for macOS that can be used to wrap arbitrary Cocoa views (i.e., NSView subclasses) and insert them into Qt hierarchies |
QMacNativeWidget |
Widget for macOS that provides a way to put Qt widgets into Cocoa hierarchies |
The abstract widget classes are base classes. They are not usable as standalone classes but provide functionality when they are subclassed.
QDialog |
The base class of dialog windows |
QAbstractButton |
The abstract base class of button widgets, providing functionality common to buttons |
QAbstractScrollArea |
Scrolling area with on-demand scroll bars |
QAbstractSlider |
Integer value within a range |
QAbstractSpinBox |
Spinbox and a line edit to display values |
QFrame |
The base class of widgets that can have a frame |
Classes like splitters, tab bars, button groups, etc are used for organizing and grouping GUI primitives into more complex applications and dialogs.
QButtonGroup |
Container to organize groups of button widgets |
QGroupBox |
Group box frame with a title |
QSplitter |
Implements a splitter widget |
QSplitterHandle |
Handle functionality for the splitter |
QStackedWidget |
Stack of widgets where only one widget is visible at a time |
QTabWidget |
Stack of tabbed widgets |
QGraphicsEffect |
The base class for all graphics effects |
QGraphicsAnchor |
Represents an anchor between two items in a QGraphicsAnchorLayout |
QGraphicsAnchorLayout |
Layout where one can anchor widgets together in Graphics View |
QGraphicsGridLayout |
Grid layout for managing widgets in Graphics View |
QAbstractGraphicsShapeItem |
Common base for all path items |
QGraphicsEllipseItem |
Ellipse item that you can add to a QGraphicsScene |
QGraphicsItem |
The base class for all graphical items in a QGraphicsScene |
QGraphicsItemGroup |
Container that treats a group of items as a single item |
QGraphicsLineItem |
Line item that you can add to a QGraphicsScene |
QGraphicsObject |
Base class for all graphics items that require signals, slots and properties |
QGraphicsPathItem |
Path item that you can add to a QGraphicsScene |
QGraphicsPixmapItem |
Pixmap item that you can add to a QGraphicsScene |
QGraphicsPolygonItem |
Polygon item that you can add to a QGraphicsScene |
QGraphicsRectItem |
Rectangle item that you can add to a QGraphicsScene |
QGraphicsSimpleTextItem |
Simple text path item that you can add to a QGraphicsScene |
QGraphicsTextItem |
Text item that you can add to a QGraphicsScene to display formatted text |
QGraphicsLayout |
The base class for all layouts in Graphics View |
QGraphicsLayoutItem |
Can be inherited to allow your custom items to be managed by layouts |
QGraphicsLinearLayout |
Horizontal or vertical layout for managing widgets in Graphics View |
QGraphicsProxyWidget |
Proxy layer for embedding a QWidget in a QGraphicsScene |
QGraphicsScene |
Surface for managing a large number of 2D graphical items |
QGraphicsSceneContextMenuEvent |
Context menu events in the graphics view framework |
QGraphicsSceneDragDropEvent |
Events for drag and drop in the graphics view framework |
QGraphicsSceneEvent |
Base class for all graphics view related events |
QGraphicsSceneHelpEvent |
Events when a tooltip is requested |
QGraphicsSceneHoverEvent |
Hover events in the graphics view framework |
QGraphicsSceneMouseEvent |
Mouse events in the graphics view framework |
QGraphicsSceneMoveEvent |
Events for widget moving in the graphics view framework |
QGraphicsSceneResizeEvent |
Events for widget resizing in the graphics view framework |
QGraphicsSceneWheelEvent |
Wheel events in the graphics view framework |
QGraphicsTransform |
Abstract base class for building advanced transformations on QGraphicsItems |
QGraphicsView |
Widget for displaying the contents of a QGraphicsScene |
QGraphicsWidget |
The base class for all widget items in a QGraphicsScene |
QStyleOptionGraphicsItem |
Used to describe the parameters needed to draw a QGraphicsItem |
QGraphicsSvgItem |
QGraphicsItem that can be used to render the contents of SVG files |
QAbstractItemModel |
The abstract interface for item model classes |
QAbstractListModel |
Abstract model that can be subclassed to create one-dimensional list models |
QAbstractTableModel |
Abstract model that can be subclassed to create table models |
QModelIndex |
Used to locate data in a data model |
QPersistentModelIndex |
Used to locate data in a data model |
QAbstractProxyModel |
Base class for proxy item models that can do sorting, filtering or other data processing tasks |
QIdentityProxyModel |
Proxies its source model unmodified |
QItemSelection |
Manages information about selected items in a model |
QItemSelectionModel |
Keeps track of a view's selected items |
QItemSelectionRange |
Manages information about a range of selected items in a model |
QSortFilterProxyModel |
Support for sorting and filtering data passed between another model and a view |
QStringListModel |
Model that supplies strings to views |
QStandardItem |
Item for use with the QStandardItemModel class |
QStandardItemModel |
Generic model for storing custom data |
QFileSystemModel |
Data model for the local filesystem |
QAbstractItemDelegate |
Used to display and edit data items from a model |
QAbstractItemView |
The basic functionality for item view classes |
QColumnView |
Model/view implementation of a column view |
QDataWidgetMapper |
Mapping between a section of a data model to widgets |
QHeaderView |
Header row or header column for item views |
QItemDelegate |
Display and editing facilities for data items from a model |
QItemEditorCreator |
Makes it possible to create item editor creator bases without subclassing QItemEditorCreatorBase |
QItemEditorCreatorBase |
Abstract base class that must be subclassed when implementing new item editor creators |
QItemEditorFactory |
Widgets for editing item data in views and delegates |
QStandardItemEditorCreator |
The possibility to register widgets without having to subclass QItemEditorCreatorBase |
QListView |
List or icon view onto a model |
QListWidget |
Item-based list widget |
QListWidgetItem |
Item for use with the QListWidget item view class |
QStyledItemDelegate |
Display and editing facilities for data items from a model |
QTableView |
Default model/view implementation of a table view |
QTableWidget |
Item-based table view with a default model |
QTableWidgetItem |
Item for use with the QTableWidget class |
QTableWidgetSelectionRange |
Way to interact with selection in a model without using model indexes and a selection model |
QTreeView |
Default model/view implementation of a tree view |
QTreeWidget |
Tree view that uses a predefined tree model |
QTreeWidgetItem |
Item for use with the QTreeWidget convenience class |
QTreeWidgetItemIterator |
Way to iterate over the items in a QTreeWidget instance |
QAction |
Abstract user interface action that can be inserted into widgets |
QActionGroup |
Groups actions together |
QWidgetAction |
Extends QAction by an interface for inserting custom widgets into action based containers, such as toolbars |
QDockWidget |
Widget that can be docked inside a QMainWindow or floated as a top-level window on the desktop |
QMainWindow |
Main application window |
QMdiArea |
Area in which MDI windows are displayed |
QMdiSubWindow |
Subwindow class for QMdiArea |
QMenu |
Menu widget for use in menu bars, context menus, and other popup menus |
QMenuBar |
Horizontal menu bar |
QSizeGrip |
Resize handle for resizing top-level windows |
QStatusBar |
Horizontal bar suitable for presenting status information |
QToolBar |
Movable panel that contains a set of controls |
Classes used for customizing UI appearance and style.
QCursor |
Mouse cursor with an arbitrary shape |
QPalette |
Contains color groups for each widget state |
QColor |
Colors based on RGB, HSV or CMYK values |
QFont |
Specifies a font used for drawing text |
QFontDatabase |
Information about the fonts available in the underlying window system |
QFontInfo |
General information about fonts |
QGraphicsAnchor |
Represents an anchor between two items in a QGraphicsAnchorLayout |
QGraphicsAnchorLayout |
Layout where one can anchor widgets together in Graphics View |
QCommonStyle |
Encapsulates the common Look and Feel of a GUI |
QStyle |
Abstract base class that encapsulates the look and feel of a GUI |
QStyleFactory |
Creates QStyle objects |
QStyleHintReturn |
Style hints that return more than basic data types |
QStyleHintReturnMask |
Style hints that return a QRegion |
QStyleHintReturnVariant |
Style hints that return a QVariant |
QStyleOption |
Stores the parameters used by QStyle functions |
QStylePainter |
Convenience class for drawing QStyle elements inside a widget |
QGraphicsAnchor |
Represents an anchor between two items in a QGraphicsAnchorLayout |
QGraphicsAnchorLayout |
Layout where one can anchor widgets together in Graphics View |
QBoxLayout |
Lines up child widgets horizontally or vertically |
QHBoxLayout |
Lines up widgets horizontally |
QVBoxLayout |
Lines up widgets vertically |
QFormLayout |
Manages forms of input widgets and their associated labels |
QGridLayout |
Lays out widgets in a grid |
QLayout |
The base class of geometry managers |
QLayoutItem |
Abstract item that a QLayout manipulates |
QSpacerItem |
Blank space in a layout |
QWidgetItem |
Layout item that represents a widget |
QSizePolicy |
Layout attribute describing horizontal and vertical resizing policy |
QStackedLayout |
Stack of widgets where only one widget is visible at a time |
QButtonGroup |
Container to organize groups of button widgets |
QGroupBox |
Group box frame with a title |
QStackedWidget |
Stack of widgets where only one widget is visible at a time |