简体   繁体   中英

How to determine the visible area of QQuickPaintedItem?

Is there an equivalent of Win32 GetUpdateRect function in QML? For example, if a control derived from QQuickPaintedItem is inside Flickable is there a way to get the smallest rectangle that should be redrawn in

QQuickPaintedItem::paint(QPainter *painter)

?

When you call QQuickPaintedItem::update() , the given QRect parameter will be set as clip bounding rect for your QPainter in QQuickPaintedItem::paint .

So, if you want to redraw a specific region of your item, just call QQuickPaintedItem::update() with the rect you want to repaint.

item->update(QRect(10, 20, 30, 20));

void CharacterItem::paint(QPainter *painter)
{
    qDebug() << painter->clipBoundingRect() << painter->clipPath();
}

It will display:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM