qt - QQuickPaintedItem的可视区域如何确定?
问题描述
QML中是否有等效于Win32 GetUpdateRect 函数?例如,如果从 QQuickPaintedItem 派生的控件位于 Flickable 内部,是否有办法获得应在其中重绘的最小矩形
QQuickPaintedItem::paint(QPainter *painter)
?
解决方案
当您调用QQuickPaintedItem::update()
时,给定的QRect
参数将被设置为您的in的剪辑边界矩形。QPainter
QQuickPaintedItem::paint
因此,如果您想重绘项目的特定区域,只需调用QQuickPaintedItem::update()
您要重绘的矩形即可。
item->update(QRect(10, 20, 30, 20));
void CharacterItem::paint(QPainter *painter)
{
qDebug() << painter->clipBoundingRect() << painter->clipPath();
}
它将显示:
QRectF(10,20 30x20)
QPainterPath: Element count=5
-> MoveTo(x=10, y=20)
-> LineTo(x=40, y=20)
-> LineTo(x=40, y=40)
-> LineTo(x=10, y=40)
-> LineTo(x=10, y=20)
推荐阅读
- oracle - 从包含 Oracle 中的命名空间的 XMLTYPE 中提取标记值
- c# - 从 Visual Studio 2013 更新到 2019 后,注册 Tagprefix="SharePoint" 自动添加到 aspx 页面
- javascript - 带有 v-if 或计算属性的 V-for
- python - 通过调用第一部分提取索引第二部分
- spring-boot - 500 内部服务器错误:[{“错误”:[“解析值时遇到意外字符:%。路径'',第 0 行,位置 0。”]}]
- vue.js - Vue 3.0 + Nuxt:模板中仍然限制“恰好一个根元素”(和:键绑定)
- mysql - 检查数据库的凭据是否对 Laravel 有效
- html - 如何垂直对齐使用“vh”单位的按钮文本?
- python - 嗨,如何根据python中的日期删除AWS中的文件?
- android - Flutter IAP - 您已经拥有此项目的错误