Qt GUI
Qt GUI模块提供窗口系统集成, 事件处理, OpenGL和OpenGL ES集成, 2D图形, 基本图像, 字体和文本等相关类. 这些类可以由Qt的UI技术内部使用, 也可以直接使用. 例如, 使用低级OpenGL ES图形API编写应用程序.
对于应用程序的UI开发人员, Qt提供更高级别的API, 如Qt Quick, 比Qt GUI模块更适合UI编程.
开始使用
To include the definitions of the module's classes, use the following directive:
#include <QtGui>
If you use qmake to build your projects, Qt GUI is included by default. To disable Qt GUI, add the following line to your .pro
file:
QT -= gui
应用程序窗口
Qt GUI模块最重要的类是 QGuiApplication 和 QWindow. QGuiApplication 包含主事件循环, 处理和调度来自窗口系统和其他源的所有事件. 它还处理程序初始化和结束.
The QWindow 表示底层窗口系统的一个窗口. 它提供一组虚拟函数, 处理窗口系统的事件 (QEvent) , 如触控输入, 曝光, 焦点, 按键和形状更改.
2D图形
Qt GUI模块包含2D图形, 图像, 字体和高级排版等相关类.
创建QSurface::RasterSurface类型的 QWindow, 可以与 QBackingStore 和 QPainter(Qt高度优化的2D矢量图形API)结合使用. QPainter 支持线条, 多边形, 矢量路径, 图像和文本绘制. 详见 Paint System 和 Raster Window Example.
Qt可以使用 QImage 和 QPixmap 加载和保存图像. 默认情况下, Qt支持最常见的图像格式, 包括JPEG和PNG等. 用户可以通过 QImageIOPlugin 类添加对其他格式的支持. 详见 Reading and Writing Image Files
Qt中的排版使用 QTextDocument 完成, 它使用 QPainter 与Qt的字体类(主要是 QFont)相结合. 与文本和字体处理相比, 更喜欢低级API的应用程序, 可以使用 QRawFont 和 QGlyphRun 等.
OpenGL和OpenGL ES集成
QWindow 支持OpenGL和OpenGL渲染, 具体内容依赖平台提供. 启用OpenGL渲染的方式: 创建QSurface::OpenGLSurface类型的 QWindow , 并使用QSurfaceFormat设置格式属性, 然后创建 QOpenGLContext 管理OpenGL上下文. 此外, Qt有 QOpenGLPaintDevice, 它可以使用OpenGL加速 QPainter 渲染, Qt也具有QOpenGLFunctions等便捷类, 简化OpenGL代码编写, 隐藏扩展处理的复杂性及OpenGL ES 2和桌面OpenGL的差异. QOpenGLFunctions 允许应用程序在桌面OpenGL上使用OpenGL ES 2的所有函数, 而无需手动解析OpenGL的函数指针, 从而允许跨平台开发移动或嵌入式设备的应用程序. 如下, 还有一些类将OpenGL本地函数封装成简单的Qt API:
- QOpenGLBuffer
- QOpenGLFramebufferObject
- QOpenGLShaderProgram
- QOpenGLTexture
- QOpenGLDebugLogger
- QOpenGLTimerQuery
- QOpenGLVertexArrayObject
最后, 为了更好地支持OpenGL新版本(3.0及更高版本), Qt还提供一种基于版本的函数封装机制: QOpenGLFunction_N_N类系列实现给定OpenGL版本和配置文件的所有函数, 从而轻松开发依赖现代, 仅支持桌面的OpenGL特性的应用程序. 详见 OpenGL Window Example.
Qt GUI模块还包含一些数学类, 辅助3D图形相关的数学操作. 这些类包含 QMatrix4x4, QVector4D 和 QQuaternion
QSurface::OpenGLSurface类型的 QWindow 可以与 QPainter 和 QOpenGLPaintDevice 结合使用, 通过牺牲一些视觉效果获取OpenGL硬件加速.
Qt GUI Prior to Qt 5.0
Prior to Qt 5.0, the Qt GUI module was the monolithic container for all things relating to graphical user interfaces in Qt, and included the Qt widget set, the item views, the graphics view framework and also printing. Starting Qt 5, these classes have been moved to the Qt Widgets module. Printing has been moved to the Qt Print Support module. Please note that these modules can be excluded from a Qt installation.
Qt GUI now contains only a small set of enablers, which are generally useful for all graphical applications.
拖拽
Licenses and Attributions
Qt GUI is available under commercial licenses from The Qt Company. In addition, it is available under the GNU Lesser General Public License, version 3, or the GNU General Public License, version 2. See Qt Licensing for further details.
Furthermore Qt GUI potentially contains third party modules under following permissive licenses:
BSD 3-clause "New" or "Revised" License | |
BSD 2-clause "Simplified" License | |
Public Domain | |
BSD 2-clause "Simplified" License | |
BSD 3-clause "New" or "Revised" License | |
Freetype Project License or GNU General Public License v2.0 only | |
BSD 3-clause "New" or "Revised" License | |
Freetype Project License or GNU General Public License v2.0 only | |
MIT License | |
MIT License | |
BSD 3-clause "New" or "Revised" License | |
Independent JPEG Group License | |
libpng License | |
Apache License 2.0 | |
MIT License | |
MIT License | |
MIT License | |
BSD 2-clause "Simplified" License and Imlib2 License | |
Public Domain | |
MIT License | |
GNU Library General Public License v2 or later | |
MIT Licenses (with no-advertisement clause) |