![]() |
Qt 6.x
The Qt SDK
|
The QRegion class specifies a clip region for a painter. More...
#include <qregion.h>
Public Types | |
enum | RegionType { Rectangle , Ellipse } |
Specifies the shape of the region to be created. More... | |
typedef const QRect * | const_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
Public Member Functions | |
QRegion () | |
Constructs an empty region. | |
QRegion (int x, int y, int w, int h, RegionType t=Rectangle) | |
Constructs a rectangular or elliptic region. | |
QRegion (const QRect &r, RegionType t=Rectangle) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Create a region based on the rectangle r with region type t. | |
QRegion (const QPolygon &pa, Qt::FillRule fillRule=Qt::OddEvenFill) | |
Constructs a polygon region from the point array a with the fill rule specified by fillRule. | |
QRegion (const QRegion ®ion) | |
Constructs a new region which is equal to region r. | |
QRegion (QRegion &&other) noexcept | |
QRegion (const QBitmap &bitmap) | |
Constructs a region from the bitmap bm. | |
~QRegion () | |
QRegion & | operator= (const QRegion &) |
Assigns r to this region and returns a reference to the region. | |
void | swap (QRegion &other) noexcept |
bool | isEmpty () const |
Returns true if the region is empty; otherwise returns false . | |
bool | isNull () const |
const_iterator | begin () const noexcept |
const_iterator | cbegin () const noexcept |
const_iterator | end () const noexcept |
const_iterator | cend () const noexcept |
const_reverse_iterator | rbegin () const noexcept |
const_reverse_iterator | crbegin () const noexcept |
const_reverse_iterator | rend () const noexcept |
const_reverse_iterator | crend () const noexcept |
bool | contains (const QPoint &p) const |
Returns true if the region contains the point p; otherwise returns false . | |
bool | contains (const QRect &r) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the region overlaps the rectangle r; otherwise returns false . | |
void | translate (int dx, int dy) |
Translates (moves) the region dx along the X axis and dy along the Y axis. | |
void | translate (const QPoint &p) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Translates the region {point}{.x()} along the x axis and {point}{.y()} along the y axis, relative to the current position. | |
QRegion | translated (int dx, int dy) const |
QRegion | translated (const QPoint &p) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QRegion | united (const QRegion &r) const |
QRegion | united (const QRect &r) const |
QRegion | intersected (const QRegion &r) const |
QRegion | intersected (const QRect &r) const |
QRegion | subtracted (const QRegion &r) const |
QRegion | xored (const QRegion &r) const |
bool | intersects (const QRegion &r) const |
bool | intersects (const QRect &r) const |
QRect | boundingRect () const noexcept |
Returns the bounding rectangle of this region. | |
void | setRects (const QRect *rect, int num) |
Sets the region using the array of rectangles specified by rects and number. | |
int | rectCount () const noexcept |
QRegion | operator| (const QRegion &r) const |
Applies the united() function to this region and r. | |
QRegion | operator+ (const QRegion &r) const |
Applies the united() function to this region and r. | |
QRegion | operator+ (const QRect &r) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QRegion | operator& (const QRegion &r) const |
Applies the intersected() function to this region and r. | |
QRegion | operator& (const QRect &r) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QRegion | operator- (const QRegion &r) const |
Applies the subtracted() function to this region and r. | |
QRegion | operator^ (const QRegion &r) const |
Applies the xored() function to this region and r. | |
QRegion & | operator|= (const QRegion &r) |
Applies the united() function to this region and r and assigns the result to this region. | |
QRegion & | operator+= (const QRegion &r) |
Applies the united() function to this region and r and assigns the result to this region. | |
QRegion & | operator+= (const QRect &r) |
Returns a region that is the union of this region with the specified rect. | |
QRegion & | operator&= (const QRegion &r) |
Applies the intersected() function to this region and r and assigns the result to this region. | |
QRegion & | operator&= (const QRect &r) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QRegion & | operator-= (const QRegion &r) |
Applies the subtracted() function to this region and r and assigns the result to this region. | |
QRegion & | operator^= (const QRegion &r) |
Applies the xored() function to this region and r and assigns the result to this region. | |
bool | operator== (const QRegion &r) const |
Returns true if the region is equal to r; otherwise returns false. | |
bool | operator!= (const QRegion &r) const |
Returns true if this region is different from the other region; otherwise returns false . | |
operator QVariant () const | |
Returns the region as a QVariant. | |
Friends | |
struct | QRegionPrivate |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &, const QRegion &) |
Writes the region r to the stream s and returns a reference to the stream. | |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &, QRegion &) |
Reads a region from the stream s into r and returns a reference to the stream. | |
Q_GUI_EXPORT friend bool | qt_region_strictContains (const QRegion ®ion, const QRect &rect) |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &s, const QRegion &r) |
Writes the region r to the stream s and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &s, QRegion &r) |
Reads a region from the stream s into r and returns a reference to the stream. | |
The QRegion class specifies a clip region for a painter.
\inmodule QtGui
QRegion is used with QPainter::setClipRegion() to limit the paint area to what needs to be painted. There is also a QWidget::repaint() function that takes a QRegion parameter. QRegion is the best tool for minimizing the amount of screen area to be updated by a repaint.
This class is not suitable for constructing shapes for rendering, especially as outlines. Use QPainterPath to create paths and shapes for use with QPainter.
QRegion is an \l{implicitly shared} class.
enum QRegion::RegionType |
QRegion::QRegion | ( | ) |
Constructs an empty region.
Referenced by operator&=(), and operator+=().
QRegion::QRegion | ( | int | x, |
int | y, | ||
int | w, | ||
int | h, | ||
RegionType | t = Rectangle |
||
) |
Constructs a rectangular or elliptic region.
If t is Rectangle
, the region is the filled rectangle (x, y, w, h). If t is Ellipse
, the region is the filled ellipse with center at (x + w / 2, y + h / 2) and size (w ,h).
Definition at line 160 of file qregion.cpp.
QRegion::QRegion | ( | const QRect & | r, |
RegionType | t = Rectangle |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Create a region based on the rectangle r with region type t.
If the rectangle is invalid a null region will be created.
QRegion::QRegion | ( | const QPolygon & | a, |
Qt::FillRule | fillRule = Qt::OddEvenFill |
||
) |
Constructs a polygon region from the point array a with the fill rule specified by fillRule.
If fillRule is \l{Qt::WindingFill}, the polygon region is defined using the winding algorithm; if it is \l{Qt::OddEvenFill}, the odd-even fill algorithm is used.
QRegion::QRegion | ( | const QRegion & | region | ) |
Constructs a new region which is equal to region r.
|
inlinenoexcept |
QRegion::QRegion | ( | const QBitmap & | bm | ) |
Constructs a region from the bitmap bm.
The resulting region consists of the pixels in bitmap bm that are Qt::color1, as if each pixel was a 1 by 1 rectangle.
This constructor may create complex regions that will slow down painting when used. Note that drawing masked pixmaps can be done much faster using QPixmap::setMask().
QRegion::~QRegion | ( | ) |
Destroys the region.
|
noexcept |
Returns a const_iterator pointing to the beginning of the range of non-overlapping rectangles that make up the region.
The union of all the rectangles is equal to the original region.
Referenced by QPaintEngineEx::clip(), QXcbBackingStore::endPaint(), QClipData::initialize(), qRegionToWinRegion(), qt_regionToPath(), QTest::toString(), and QSGSoftwareRenderableNode::update().
|
noexcept |
Returns the bounding rectangle of this region.
An empty region gives a rectangle that is QRect::isNull().
Referenced by _q_paintIntoCache(), QWindowsDirect2DPaintEngine::begin(), QRasterPaintEngine::clip(), QWindowsVistaStylePrivate::drawBackgroundDirectly(), QQC2::QWindowsXPStylePrivate::drawBackgroundDirectly(), QGraphicsScenePrivate::drawItems(), QTreeView::drawTree(), QWidgetPrivate::drawWidget(), QWidgetPrivate::effectiveRectFor(), fillRegion(), QGraphicsViewPrivate::findItems(), QBackingStore::flush(), QOffscreenBackingStore::flush(), QWindowsBackingStore::flush(), QXcbNativeBackingStore::flush(), QXcbBackingStore::flush(), QCocoaWindow::handleExposeEvent(), intersects(), QWidgetPrivate::paintSiblingsRecursive(), QQnxRasterWindow::post(), QWindowsDirect2DWindow::present(), QXcbBackingStoreImage::put(), qt_hrgn_from_qregion(), QQC2::qt_hrgn_from_qregion(), qt_regionToPath(), QWidgetPrivate::render(), QXcbSystemTrayBackingStore::render(), QWidgetPrivate::render_helper(), QAndroidPlatformOpenGLWindow::repaint(), QXcbNativeBackingStore::resize(), QRasterBackingStore::scroll(), QCALayerBackingStore::scroll(), QClipData::setClipRegion(), QQC2_NAMESPACE::QMacStyle::sizeFromContents(), QMacStyle::sizeFromContents(), QWidgetPrivate::subtractOpaqueSiblings(), QWaylandSurfacePrivate::surface_commit(), QRasterPaintEnginePrivate::systemStateChanged(), QOpenGL2PaintEngineExPrivate::systemStateChanged(), QPicturePaintEngine::updateClipRegion(), QOpenGL2PaintEngineExPrivate::updateClipScissorTest(), QGraphicsViewPrivate::updateRegion(), and QPaintEnginePrivate::updateSystemClip().
|
inlinenoexcept |
|
inlinenoexcept |
bool QRegion::contains | ( | const QPoint & | p | ) | const |
Returns true
if the region contains the point p; otherwise returns false
.
Referenced by QSGAbstractSoftwareRenderer::optimizeRenderList(), QDockAreaLayoutInfo::paintSeparators(), QDockAreaLayout::paintSeparators(), and QFlickGestureRecognizer::recognize().
bool QRegion::contains | ( | const QRect & | r | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true
if the region overlaps the rectangle r; otherwise returns false
.
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
Returns a const_iterator pointing to one past the end of non-overlapping rectangles that make up the region.
The union of all the rectangles is equal to the original region.
Referenced by QXcbBackingStore::endPaint(), qRegionToWinRegion(), and qt_regionToPath().
Returns a region which is the intersection of this region and the given rect.
Returns a region which is the intersection of this region and r.
Region Intersection
The figure shows the intersection of two elliptical regions.
Referenced by QSGSoftwareRenderableNode::addDirtyRegion(), QBlitterPaintEngine::fillRect(), QOpenGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QAlphaPaintEnginePrivate::fullyContained(), operator&(), operator&(), QXcbBackingStoreImage::scroll(), QWidgetPrivate::scrollRect(), QX11PaintEngine::updateClipRegion_dev(), and QSGSoftwareRenderableNodeUpdater::visit().
bool QRegion::intersects | ( | const QRect & | rect | ) | const |
Returns true
if this region intersects with rect, otherwise returns false
.
bool QRegion::intersects | ( | const QRegion & | region | ) | const |
Returns true
if this region intersects with region, otherwise returns false
.
Definition at line 613 of file qregion.cpp.
References boundingRect(), isEmpty(), rect_intersects(), and rectCount().
Referenced by QSGSoftwareRenderableNode::addDirtyRegion(), QWidgetRepaintManager::bltRect(), QAlphaPaintEnginePrivate::canSeeTroughBackground(), QFbScreen::doRedraw(), QGraphicsScenePrivate::drawSubtreeRecursive(), QOpenGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QXcbBackingStoreImage::flushScrolledRegion(), QWidgetPrivate::overlappedRegion(), QXcbBackingStoreImage::preparePaint(), and QSGSoftwareRenderableNode::subtractDirtyRegion().
bool QRegion::isEmpty | ( | ) | const |
Returns true
if the region is empty; otherwise returns false
.
An empty region is a region that contains no points.
Example:
Referenced by _q_paintIntoCache(), QOpenGL2PaintEngineEx::begin(), QQnxRasterWindow::blitPreviousToCurrent(), QFbScreen::doRedraw(), QBsdFbScreen::doRedraw(), QIntegrityFbScreen::doRedraw(), QLinuxFbDrmScreen::doRedraw(), QLinuxFbScreen::doRedraw(), QVncScreen::doRedraw(), QWindowsVistaStylePrivate::drawBackgroundDirectly(), QQC2::QWindowsXPStylePrivate::drawBackgroundDirectly(), QWindowsVistaStylePrivate::drawBackgroundThruNativeBuffer(), QQC2::QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QGraphicsScenePrivate::drawItemHelper(), QWidgetPrivate::drawWidget(), QtWaylandClient::QWaylandXdgSurface::handleExpose(), QCocoaWindow::handleExposeEvent(), QBackingStore::hasStaticContents(), intersects(), QWidgetPrivate::invalidateBackingStore(), QWidgetPrivate::invalidateBackingStore_resizeHelper(), QWidgetRepaintManager::isDirty(), QSGSoftwareRenderableNode::isDirtyRegionEmpty(), QCocoaWindow::isOpaque(), QWidgetRepaintManager::markDirty(), QWidgetRepaintManager::markNeedsFlush(), QMdiSubWindow::mouseMoveEvent(), QWidgetPrivate::moveRect(), QSGAbstractSoftwareRenderer::optimizeRenderList(), QPaintDeviceWindowPrivate::paint(), QTabBar::paintEvent(), QQnxRasterWindow::post(), QWidgetPrivate::prepareToRender(), qt_mac_clip_cg(), QQuickShapeSoftwareRenderNode::render(), QWidgetPrivate::render(), QWidget::render(), QWidgetPrivate::render_helper(), QSGSoftwareRenderableNode::renderNode(), QQuickWidgetPrivate::renderSceneGraph(), QWindowsBackingStore::resize(), scaleRegion(), QQC2::scaleRegion(), QCALayerBackingStore::scroll(), QWidgetPrivate::scrollRect(), QCoreGraphicsPaintEnginePrivate::setClip(), QWidget::setMask(), QWasmWindow::setMask(), QCocoaWindow::setMask(), QWindowsWindow::setMask(), QXcbWindow::setMask(), QPaintEnginePrivate::setSystemTransformAndViewport(), QPaintEnginePrivate::setSystemViewport(), QWidgetRepaintManager::staticContents(), QSGSoftwareRenderableNode::subtractDirtyRegion(), QWidgetPrivate::subtractOpaqueSiblings(), QWidgetRepaintManager::sync(), QRasterPaintEnginePrivate::systemStateChanged(), QOpenGL2PaintEngineExPrivate::systemStateChanged(), QTest::toString(), QSGSoftwareRenderableNode::update(), QX11PaintEngine::updateBrush(), QX11PaintEngine::updateClipRegion_dev(), QMdiSubWindowPrivate::updateMask(), QX11PaintEngine::updatePen(), QPaintEnginePrivate::updateSystemClip(), QApplication::widgetAt(), src_gui_painting_qregion_unix::wrapper(), and QtWaylandClient::QWaylandXdgSurface::xdg_surface_configure().
bool QRegion::isNull | ( | ) | const |
Returns true
if the region is empty; otherwise returns false
. An empty region is a region that contains no points. This function is the same as isEmpty
Referenced by QSGSoftwareRenderableNodeUpdater::endVisit(), QXcbBackingStoreImage::flushScrolledRegion(), QSGAbstractSoftwareRenderer::optimizeRenderList(), QCALayerBackingStore::resize(), QTest::toString(), QWasmBackingStore::updateTexture(), and QSGSoftwareRenderableNodeUpdater::visit().
QRegion::operator QVariant | ( | ) | const |
Returns the region as a QVariant.
Definition at line 549 of file qregion.cpp.
References QVariant::fromValue().
|
inline |
Returns true
if this region is different from the other region; otherwise returns false
.
Definition at line 97 of file qregion.h.
References operator==().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 433 of file qregion.cpp.
References intersected().
Applies the intersected() function to this region and r.
r1&r2
is equivalent to r1.intersected(r2)
.
Definition at line 426 of file qregion.cpp.
References intersected().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 511 of file qregion.cpp.
References QRegion().
Applies the intersected() function to this region and r and assigns the result to this region.
r1&=r2
is equivalent to r1
= r1.intersected(r2).
Definition at line 498 of file qregion.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 417 of file qregion.cpp.
References united().
Applies the united() function to this region and r.
r1+r2
is equivalent to r1.united(r2)
.
Definition at line 410 of file qregion.cpp.
References united().
Returns a region that is the union of this region with the specified rect.
Definition at line 483 of file qregion.cpp.
References QRegion(), and operator+=().
Applies the united() function to this region and r and assigns the result to this region.
r1+=r2
is equivalent to {r1
= r1.united(r2)}.
Referenced by operator+=().
Applies the subtracted() function to this region and r.
r1-r2
is equivalent to r1.subtracted(r2)
.
Definition at line 444 of file qregion.cpp.
References subtracted().
Applies the subtracted() function to this region and r and assigns the result to this region.
r1-=r2
is equivalent to {r1
= r1.subtracted(r2)}.
Definition at line 526 of file qregion.cpp.
Assigns r to this region and returns a reference to the region.
Move-assigns other to this QRegion instance.
bool QRegion::operator== | ( | const QRegion & | r | ) | const |
Returns true
if the region is equal to r; otherwise returns false.
Applies the xored() function to this region and r.
r1^r2
is equivalent to r1.xored(r2)
.
Definition at line 453 of file qregion.cpp.
References xored().
Applies the xored() function to this region and r and assigns the result to this region.
r1^=r2
is equivalent to {r1
= r1.xored(r2)}.
Definition at line 536 of file qregion.cpp.
Applies the united() function to this region and r.
r1|r2
is equivalent to r1.united(r2)
.
Definition at line 401 of file qregion.cpp.
References united().
Applies the united() function to this region and r and assigns the result to this region.
r1|=r2
is equivalent to {r1
= r1.united(r2)}.
Definition at line 463 of file qregion.cpp.
|
inlinenoexcept |
Returns a const_reverse_iterator pointing to the beginning of the range of non-overlapping rectangles that make up the region.
The union of all the rectangles is equal to the original region.
Definition at line 53 of file qregion.h.
Referenced by QQnxRasterWindow::blitPreviousToCurrent().
|
noexcept |
Returns the number of rectangles that this region is composed of. Same as {end() - begin()}.
Referenced by _q_paintIntoCache(), QPaintEngineEx::clip(), QRasterPaintEngine::clip(), QTreeView::drawTree(), QGraphicsViewPrivate::findItems(), QClipData::initialize(), intersects(), qRegionToXcbRectangleList(), qt_hrgn_from_qregion(), QQC2::qt_hrgn_from_qregion(), qt_mac_scale_region(), qt_regionToPath(), QSGSoftwareRenderableNode::renderNode(), scaledRegion(), QClipData::setClipRegion(), QOpenGL2PaintEngineExPrivate::systemStateChanged(), QTest::toString(), QSGSoftwareRenderableNode::update(), and QRfbRawEncoder::write().
|
inlinenoexcept |
Returns a const_reverse_iterator pointing to one past the end of the range of non-overlapping rectangles that make up the region.
The union of all the rectangles is equal to the original region.
Definition at line 55 of file qregion.h.
References begin().
Referenced by QQnxRasterWindow::blitPreviousToCurrent().
Sets the region using the array of rectangles specified by rects and number.
The rectangles must be optimally Y-X sorted and follow these restrictions:
\list
Referenced by QAlphaPaintEnginePrivate::canSeeTroughBackground(), qt_mac_scale_region(), and scaledRegion().
Returns a region which is r subtracted from this region.
Region Subtraction
The figure shows the result when the ellipse on the right is subtracted from the ellipse on the left ({left
- right}).
Referenced by operator-(), QSGAbstractSoftwareRenderer::optimizeRenderList(), and QSGSoftwareRenderableNode::previousDirtyRegion().
Swaps region other with this region. This operation is very fast and never fails.
Definition at line 42 of file qregion.h.
References d, other(), and qt_ptr_swap().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Translates the region {point}{.x()} along the x axis and {point}{.y()} along the y axis, relative to the current position.
Positive values move the region to the right and down.
Translates to the given point.
Definition at line 62 of file qregion.h.
References translate().
Referenced by translate().
void QRegion::translate | ( | int | dx, |
int | dy | ||
) |
Translates (moves) the region dx along the X axis and dy along the Y axis.
Referenced by QBackingStore::flush(), QWidgetPrivate::moveRect(), QWidgetPrivate::paintSiblingsRecursive(), QGraphicsItem::scroll(), QWidgetPrivate::scrollRect(), QWidget::setMask(), QWidgetRepaintManager::staticContents(), QWidgetPrivate::subtractOpaqueSiblings(), and QPaintEnginePrivate::updateSystemClip().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a copy of the regtion that is translated {p}{.x()} along the x axis and {p}{.y()} along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
Definition at line 64 of file qregion.h.
References translated().
Referenced by translated().
QRegion QRegion::translated | ( | int | dx, |
int | dy | ||
) | const |
Returns a copy of the region that is translated dx along the x axis and dy along the y axis, relative to the current position. Positive values move the region to the right and down.
Definition at line 593 of file qregion.cpp.
References ret.
Referenced by QWidget::childrenRegion(), QWindowsVistaStylePrivate::drawBackgroundDirectly(), QQC2::QWindowsXPStylePrivate::drawBackgroundDirectly(), QtWaylandClient::QWaylandShmBackingStore::flush(), QWidgetRepaintManager::markDirty(), QWidgetRepaintManager::markNeedsFlush(), QWidgetPrivate::overlappedRegion(), QTableView::paintEvent(), QXcbBackingStoreImage::put(), QFlickGestureRecognizer::recognize(), QWidgetPrivate::render(), QHighDpi::scale(), QCALayerBackingStore::scroll(), QPixmap::scroll(), QGraphicsView::scrollContentsBy(), QWidgetPrivate::subtractOpaqueSiblings(), and QGraphicsPixmapItemPrivate::updateShape().
Returns a region which is the union of this region and the given rect.
Returns a region which is the union of this region and r.
Region Union
The figure shows the union of two elliptical regions.
Referenced by operator+(), operator+(), and operator|().
Returns a region which is the exclusive or (XOR) of this region and r.
Region XORed
The figure shows the exclusive or of two elliptical regions.
Referenced by operator^().
|
friend |
Writes the region r to the stream s and returns a reference to the stream.
Definition at line 313 of file qregion.cpp.
|
related |
Writes the region r to the stream s and returns a reference to the stream.
Definition at line 313 of file qregion.cpp.
|
friend |
Reads a region from the stream s into r and returns a reference to the stream.
Definition at line 347 of file qregion.cpp.
|
related |
Reads a region from the stream s into r and returns a reference to the stream.
Definition at line 347 of file qregion.cpp.
|
friend |