qt-渲染原理( 六 )


的常见用途是在小部件的绘制事件中:构造和自定义(例如设置钢笔或画笔)画家 。然后画 。记得在绘制后销毁对象 。
绘制过程
所有的绘制在中间都必然要经过 。只不过是它的一个派生 , 
现在主要提供的是Qt自带的光栅化引擎(),Qt在他所有支持的平台上 , 提供了一个功能完备的光栅化引擎 。
在, X11 和 macOS平台上 , Qt自带的光栅化引擎都是这个基础类的默认的绘制方法的提供者 , 亦或是的绘制方法的提供者 。当然有一些特殊的绘制设备的绘制引擎不提供对应的绘制方法 , 这时候就会调用默认的光栅化引擎 。而根据所要绘制的内容 , 来区分绘制逻辑 , 比方说涂色采用填充、统一刷新的方式;字体绘制要调用字体图元相关绘制逻辑等等 。
QPaintEngine *QImage::paintEngine() const{if (!d)return 0;if (!d->paintEngine) {QPaintDevice *paintDevice = const_cast(this);QPaintEngine *paintEngine = 0;QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();if (platformIntegration)paintEngine = platformIntegration->createImagePaintEngine(paintDevice);d->paintEngine = paintEngine ? paintEngine : new QRasterPaintEngine(paintDevice);}return d->paintEngine;}
只是的派生类 。我也说平台下默认的 Qt 绘制是使用指令集的 。原因就在于默认条件下 , 绝大部分的是选择用
所有的表层绘制都要经过绘制引擎来向下传递绘制信息 。这是 Qt 作为一个高级框架的闪光点 , 在其他的 Qt 模块也有类似发现 , 比如控件的绘制上 。这样看来 Qt 这个框架能给我们的 , 除了代码逻辑本身 , 还有设计 。
在平台 默认的 Qt 绘制 , 最终到底层是直接调用指令集指令的而不是API  , 
这也是 Qt 的性能的保障 。如果想探究指令集部分的使用 , 需要到源码目录 \src\gui\:
thetheme:
路径 :D:\Qt\5.9.8\Src\\src\gui\\.cpp
在函数 void (const&, const&, const&, int &argc, char **argv)中确定了平台的主题:调试以平台为例
// Create the platform theme:// 1) Fetch the platform name from the environment if present.QStringList themeNames;if (!platformThemeName.isEmpty())themeNames.append(platformThemeName);// 2) Ask the platform integration for a list of theme namesthemeNames += QGuiApplicationPrivate::platform_integration->themeNames();// 3) Look for a theme plugin.for (const QString &themeName : qAsConst(themeNames)) {QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);if (QGuiApplicationPrivate::platform_theme)break;}// 4) If no theme plugin was found ask the platform integration to// create a themeif (!QGuiApplicationPrivate::platform_theme) {for (const QString &themeName : qAsConst(themeNames)) {QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);if (QGuiApplicationPrivate::platform_theme)break;}// No error message; not having a theme plugin is allowed.}// 5) Fall back on the built-in "null" platform theme.if (!QGuiApplicationPrivate::platform_theme)QGuiApplicationPrivate::platform_theme = new QPlatformTheme;
1) Fetch thename from theif .
首先读取环境变量 , 确定主题 , 跳过
2) Ask thefor a list of theme names
+= te::->();
QStringList QWindowsIntegration::themeNames() const{return QStringList(QLatin1String(QWindowsTheme::name));}
在平台上是 , 返回的是中的name,该name是一个常量:const char *::name = "";(路径D:\Qt\5.9.8\Src\\src\\\\.cpp)
3) Look for a theme
查找主题插件 , 没有找到