首页 > 解决方案 > QQuickPaintedItem的可视区域如何确定?

问题描述

QML中是否有等效于Win32 GetUpdateRect 函数?例如,如果从 QQuickPaintedItem 派生的控件位于 Flickable 内部,是否有办法获得应在其中重绘的最小矩形

QQuickPaintedItem::paint(QPainter *painter)

?

标签: qtqml

解决方案


当您调用QQuickPaintedItem::update()时,给定的QRect参数将被设置为您的in的剪辑边界矩形QPainterQQuickPaintedItem::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)

推荐阅读