简体   繁体   English

如何确定QQuickPaintedItem的可见区域?

[英]How to determine the visible area of QQuickPaintedItem?

Is there an equivalent of Win32 GetUpdateRect function in QML? QML中是否有等效的Win32 GetUpdateRect函数 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派生的控件在Flickable内,有一种方法可以获得应该重绘的最小矩形

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 . 当您调用QQuickPaintedItem::update() ,给定的QRect参数将被设置为QQuickPaintedItem::paint QPainter 剪辑边界rect

So, if you want to redraw a specific region of your item, just call QQuickPaintedItem::update() with the rect you want to repaint. 因此,如果要重新绘制项目的特定区域,只需使用要重绘的矩形调用QQuickPaintedItem::update()

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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