QRegion 类

The QRegion 类为描绘器指定裁剪区域。 更多...

头: #include <QRegion>
qmake: QT += gui

公共类型

enum RegionType { Rectangle, Ellipse }
typedef const_iterator
typedef const_reverse_iterator

公共函数

QRegion ()
QRegion (int x , int y , int w , int h , QRegion::RegionType t = Rectangle)
QRegion (const QRect & r , QRegion::RegionType t = Rectangle)
QRegion (const QPolygon & a , Qt::FillRule fillRule = Qt::OddEvenFill)
QRegion (const QRegion & r )
QRegion (QRegion && other )
QRegion (const QBitmap & bm )
QRegion::const_iterator begin () const
QRect boundingRect () const
QRegion::const_iterator cbegin () const
QRegion::const_iterator cend () const
bool contains (const QPoint & p ) const
bool contains (const QRect & r ) const
QRegion::const_reverse_iterator crbegin () const
QRegion::const_reverse_iterator crend () const
QRegion::const_iterator end () const
QRegion intersected (const QRegion & r ) const
QRegion intersected (const QRect & rect ) const
bool intersects (const QRegion & region ) const
bool intersects (const QRect & rect ) const
bool isEmpty () const
bool isNull () const
QRegion::const_reverse_iterator rbegin () const
int rectCount () const
QRegion::const_reverse_iterator rend () const
void setRects (const QRect * rects , int number )
QRegion subtracted (const QRegion & r ) const
void swap (QRegion & other )
void translate (int dx , int dy )
void translate (const QPoint & point )
QRegion translated (int dx , int dy ) const
QRegion translated (const QPoint & p ) const
QRegion united (const QRegion & r ) const
QRegion united (const QRect & rect ) const
QRegion xored (const QRegion & r ) const
QVariant operator QVariant () const
bool operator!= (const QRegion & other ) const
const QRegion operator& (const QRegion & r ) const
const QRegion operator& (const QRect & r ) const
QRegion & operator&= (const QRegion & r )
QRegion & operator&= (const QRect & r )
const QRegion operator+ (const QRegion & r ) const
const QRegion operator+ (const QRect & r ) const
QRegion & operator+= (const QRegion & r )
QRegion & operator+= (const QRect & rect )
const QRegion operator- (const QRegion & r ) const
QRegion & operator-= (const QRegion & r )
QRegion & operator= (const QRegion & r )
QRegion & operator= (QRegion && other )
bool operator== (const QRegion & r ) const
const QRegion operator^ (const QRegion & r ) const
QRegion & operator^= (const QRegion & r )
const QRegion operator| (const QRegion & r ) const
QRegion & operator|= (const QRegion & r )
QDataStream & operator<< (QDataStream & s , const QRegion & r )
QDataStream & operator>> (QDataStream & s , QRegion & r )

详细描述

The QRegion 类为描绘器指定裁剪区域。

QRegion 用于 QPainter::setClipRegion () 以将描绘区域限制到需要描绘的区域。另外 QWidget::repaint () 函数接受 QRegion 参数。 QRegion 是重新描绘更新屏幕区域最小化数量的最佳工具。

此类不适于构造渲染形状 (尤其作为轮廓)。使用 QPainterPath 以创建路径和形状为用于 QPainter .

QRegion 隐式共享 类。

创建和使用区域

可以从矩形、椭圆、多边形或位图创建区域。可以创建复杂区域通过组合简单区域使用 united (), intersected (), subtracted (),或 xored () (异或)。可以移动区域使用 translate ().

可以测试区域是否 isEmpty () 或者若它 contains () QPoint or QRect 。查找边界矩形可以采用 boundingRect ().

迭代片区 (采用 begin (), end (), or C++11 ranged-for loops) gives a decomposition of the region into rectangles.

使用复杂区域的范例:

void MyWidget::paintEvent(QPaintEvent *)
{
    QRegion r1(QRect(100, 100, 200, 80),    // r1: elliptic region
               QRegion::Ellipse);
    QRegion r2(QRect(100, 120, 90, 30));    // r2: rectangular region
    QRegion r3 = r1.intersected(r2);        // r3: intersection
    QPainter painter(this);
    painter.setClipRegion(r3);
    ...                                     // paint clipped graphics
}
					

另请参阅 QPainter::setClipRegion (), QPainter::setClipRect (),和 QPainterPath .

成员类型文档编制

enum QRegion:: RegionType

指定要创建的区域形状。

常量 描述
QRegion::Rectangle 0 区域覆盖整个矩形。
QRegion::Ellipse 1 区域是矩形内的椭圆。

typedef QRegion:: const_iterator

An iterator over the non-overlapping rectangles that make up the region.

所有矩形的并集等于原始区域。

QRegion 不提供可变迭代器。

该 typedef 在 Qt 5.8 引入。

另请参阅 begin () 和 end ().

typedef QRegion:: const_reverse_iterator

A reverse iterator over the non-overlapping rectangles that make up the region.

所有矩形的并集等于原始区域。

QRegion 不提供可变迭代器。

该 typedef 在 Qt 5.8 引入。

另请参阅 rbegin () 和 rend ().

成员函数文档编制

QRegion:: QRegion ()

构造空区域。

另请参阅 isEmpty ().

QRegion:: QRegion ( int x , int y , int w , int h , QRegion::RegionType t = Rectangle)

构造矩形 (或椭圆) 区域。

t is Rectangle ,区域是填充矩形 ( x , y , w , h )。若 t is Ellipse ,区域是填充椭圆具有中心 ( x + w / 2, y + h / 2) 和大小 ( w , h ).

QRegion:: QRegion (const QRect & r , QRegion::RegionType t = Rectangle)

这是重载函数。

创建区域基于矩形 r 采用片区类型 t .

若矩形无效,将创建 null 区域。

另请参阅 QRegion::RegionType .

QRegion:: QRegion (const QPolygon & a , Qt::FillRule fillRule = Qt::OddEvenFill)

构造多边形区域从点数组 a 采用填充规则指定通过 fillRule .

fillRule is Qt::WindingFill , the polygon region is defined using the winding algorithm; if it is Qt::OddEvenFill , the odd-even fill algorithm is used.

警告: This constructor can be used to create complex regions that will slow down painting when used.

QRegion:: QRegion (const QRegion & r )

构造的新区域等于区域 r .

QRegion:: QRegion ( QRegion && other )

Move-constructs a new region from region other . After the call, other 为 null。

该函数在 Qt 5.7 引入。

另请参阅 isNull ().

QRegion:: QRegion (const QBitmap & bm )

构造区域从位图 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::const_iterator QRegion:: begin () const

返回 const_iterator pointing to the beginning of the range of non-overlapping rectangles that make up the region.

所有矩形的并集等于原始区域。

该函数在 Qt 5.8 引入。

另请参阅 rbegin (), cbegin (),和 end ().

QRect QRegion:: boundingRect () const

返回此区域的边界矩形。空区域给出的矩形为 QRect::isNull ().

QRegion::const_iterator QRegion:: cbegin () const

如同 begin ().

该函数在 Qt 5.8 引入。

QRegion::const_iterator QRegion:: cend () const

如同 end ().

该函数在 Qt 5.8 引入。

bool QRegion:: contains (const QPoint & p ) const

返回 true 若区域包含点 p ;否则返回 false .

bool QRegion:: contains (const QRect & r ) const

这是重载函数。

返回 true 若区域重叠矩形 r ;否则返回 false .

QRegion::const_reverse_iterator QRegion:: crbegin () const

如同 rbegin ().

该函数在 Qt 5.8 引入。

QRegion::const_reverse_iterator QRegion:: crend () const

如同 rend ().

该函数在 Qt 5.8 引入。

QRegion::const_iterator QRegion:: end () const

返回 const_iterator pointing to one past the end of non-overlapping rectangles that make up the region.

所有矩形的并集等于原始区域。

该函数在 Qt 5.8 引入。

另请参阅 rend (), cend (),和 begin ().

QRegion QRegion:: intersected (const QRegion & r ) const

返回区域交集此区域和 r .

Region Intersection

图形展示 2 椭圆区域的交集。

该函数在 Qt 4.2 引入。

另请参阅 subtracted (), united (),和 xored ().

QRegion QRegion:: intersected (const QRect & rect ) const

返回区域交集此区域和给定 rect .

该函数在 Qt 4.4 引入。

另请参阅 subtracted (), united (),和 xored ().

bool QRegion:: intersects (const QRegion & region ) const

返回 true 若此区域相交 region ,否则返回 false .

该函数在 Qt 4.2 引入。

bool QRegion:: intersects (const QRect & rect ) const

返回 true 若此区域相交 rect ,否则返回 false .

该函数在 Qt 4.2 引入。

bool QRegion:: isEmpty () const

返回 true 若区域为空;否则返回 false 。空区域是不包含任何点的区域。

范例:

QRegion r1(10, 10, 20, 20);
r1.isEmpty();               // false
QRegion r3;
r3.isEmpty();               // true
QRegion r2(40, 40, 20, 20);
r3 = r1.intersected(r2);    // r3: intersection of r1 and r2
r3.isEmpty();               // true
r3 = r1.united(r2);         // r3: union of r1 and r2
r3.isEmpty();               // false
					

bool QRegion:: isNull () const

返回 true 若区域为空;否则返回 false 。空区域是不包含点的区域。此函数如同 isEmpty

该函数在 Qt 5.0 引入。

另请参阅 isEmpty ().

QRegion::const_reverse_iterator QRegion:: rbegin () const

返回 const_reverse_iterator pointing to the beginning of the range of non-overlapping rectangles that make up the region.

所有矩形的并集等于原始区域。

该函数在 Qt 5.8 引入。

另请参阅 begin (), crbegin (),和 rend ().

int QRegion:: rectCount () const

Returns the number of rectangles that this region is composed of. Same as end() - begin() .

该函数在 Qt 4.6 引入。

QRegion::const_reverse_iterator QRegion:: rend () const

返回 const_reverse_iterator pointing to one past the end of the range of non-overlapping rectangles that make up the region.

所有矩形的并集等于原始区域。

该函数在 Qt 5.8 引入。

另请参阅 end (), crend (),和 rbegin ().

void QRegion:: setRects (const QRect * rects , int number )

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:

  • 矩形不得相交。
  • All rectangles with a given top coordinate must have the same height.
  • No two rectangles may abut horizontally (they should be combined into a single wider rectangle in that case).
  • The rectangles must be sorted in ascending order, with Y as the major sort key and X as the minor sort key.

另请参阅 rects ().

QRegion QRegion:: subtracted (const QRegion & r ) const

返回区域为 r 减去此区域。

Region Subtraction

图形展示左侧椭圆减去右侧椭圆时的结果 ( left - right ).

该函数在 Qt 4.2 引入。

另请参阅 intersected (), united (),和 xored ().

void QRegion:: swap ( QRegion & other )

交换片区 other 与此区域。此操作非常快且从不失败。

该函数在 Qt 4.8 引入。

void QRegion:: translate ( int dx , int dy )

翻译 (移动) 区域 dx 沿 X 轴和 dy 沿 Y 轴。

void QRegion:: translate (const QPoint & point )

这是重载函数。

平移片区 point .x() 沿 X 轴和 point .y() along the y axis, relative to the current position. Positive values move the region to the right and down.

翻译为给定 point .

QRegion QRegion:: translated ( int dx , int dy ) const

Returns a copy of the region that is translated dx 沿 X 轴和 dy along the y axis, relative to the current position. Positive values move the region to the right and down.

该函数在 Qt 4.1 引入。

另请参阅 translate ().

QRegion QRegion:: translated (const QPoint & p ) const

这是重载函数。

返回的区域副本有平移 p .x() 沿 X 轴和 p .y() 沿 Y 轴,相对当前位置。正值向右下移动矩形。

该函数在 Qt 4.1 引入。

另请参阅 translate ().

QRegion QRegion:: united (const QRegion & r ) const

返回区域将并集此区域和 r .

Region Union

图形展示 2 椭圆区域的 union (并集)。

该函数在 Qt 4.2 引入。

另请参阅 intersected (), subtracted (),和 xored ().

QRegion QRegion:: united (const QRect & rect ) const

返回区域将并集此区域和给定 rect .

该函数在 Qt 4.4 引入。

另请参阅 intersected (), subtracted (),和 xored ().

QRegion QRegion:: xored (const QRegion & r ) const

返回区域 XOR (异或) 此区域和 r .

Region XORed

图形展示 2 椭圆区域的 XOR (异或)。

该函数在 Qt 4.2 引入。

另请参阅 intersected (), united (),和 subtracted ().

QVariant QRegion:: operator QVariant () const

返回区域按 QVariant

bool QRegion:: operator!= (const QRegion & other ) const

返回 true 若此区域不同于 other 区域;否则返回 false .

const QRegion QRegion:: operator& (const QRegion & r ) const

应用 intersected () 函数到此区域和 r . r1&r2 相当于 r1.intersected(r2) .

另请参阅 intersected ().

const QRegion QRegion:: operator& (const QRect & r ) const

这是重载函数。

该函数在 Qt 4.4 引入。

QRegion &QRegion:: operator&= (const QRegion & r )

应用 intersected () 函数到此区域和 r 并将结果赋值给此区域。 r1&=r2 相当于 r1 = r1.intersected(r2).

另请参阅 intersected ().

QRegion &QRegion:: operator&= (const QRect & r )

这是重载函数。

该函数在 Qt 4.4 引入。

const QRegion QRegion:: operator+ (const QRegion & r ) const

应用 united () 函数到此区域和 r . r1+r2 相当于 r1.united(r2) .

另请参阅 united () 和 operator| ().

const QRegion QRegion:: operator+ (const QRect & r ) const

这是重载函数。

该函数在 Qt 4.4 引入。

QRegion &QRegion:: operator+= (const QRegion & r )

应用 united () 函数到此区域和 r 并将结果赋值给此区域。 r1+=r2 相当于 r1 = r1.united(r2) .

另请参阅 intersected ().

QRegion &QRegion:: operator+= (const QRect & rect )

Returns a region that is the union of this region with the specified rect .

另请参阅 united ().

const QRegion QRegion:: operator- (const QRegion & r ) const

应用 subtracted () 函数到此区域和 r . r1-r2 相当于 r1.subtracted(r2) .

另请参阅 subtracted ().

QRegion &QRegion:: operator-= (const QRegion & r )

应用 subtracted () 函数到此区域和 r 并将结果赋值给此区域。 r1-=r2 相当于 r1 = r1.subtracted(r2) .

另请参阅 subtracted ().

QRegion &QRegion:: operator= (const QRegion & r )

赋值 r 到此区域并返回区域引用。

QRegion &QRegion:: operator= ( QRegion && other )

移动赋值 other 到此 QRegion 实例。

该函数在 Qt 5.2 引入。

bool QRegion:: operator== (const QRegion & r ) const

返回 true 若区域等于 r ;否则返回 false。

const QRegion QRegion:: operator^ (const QRegion & r ) const

应用 xored () 函数到此区域和 r . r1^r2 相当于 r1.xored(r2) .

另请参阅 xored ().

QRegion &QRegion:: operator^= (const QRegion & r )

应用 xored () 函数到此区域和 r 并将结果赋值给此区域。 r1^=r2 相当于 r1 = r1.xored(r2) .

另请参阅 xored ().

const QRegion QRegion:: operator| (const QRegion & r ) const

应用 united () 函数到此区域和 r . r1|r2 相当于 r1.united(r2) .

另请参阅 united () 和 operator+ ().

QRegion &QRegion:: operator|= (const QRegion & r )

应用 united () 函数到此区域和 r 并将结果赋值给此区域。 r1|=r2 相当于 r1 = r1.united(r2) .

另请参阅 united ().

相关非成员

QDataStream & operator<< ( QDataStream & s , const QRegion & r )

写入片区 r 到流 s 并返回流引用。

另请参阅 QDataStream 运算符格式 .

QDataStream & operator>> ( QDataStream & s , QRegion & r )

读取区域从流 s into r 并返回流引用。

另请参阅 QDataStream 运算符格式 .