QRegion 类

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

头: #include <QRegion>

公共类型

enum RegionType { Rectangle, Ellipse }

公共函数

QRegion ()
QRegion (int x , int y , int w , int h , RegionType t = Rectangle)
QRegion (const QPolygon & a , Qt::FillRule fillRule = Qt::OddEvenFill)
QRegion (const QRegion & r )
QRegion (const QBitmap & bm )
QRegion (const QRect & r , RegionType t = Rectangle)
QRect boundingRect () const
bool contains (const QPoint & p ) const
bool contains (const QRect & r ) const
Handle handle () 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
int rectCount () const
QVector<QRect> rects () 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
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 . The bounding rectangle can be found with boundingRect ().

函数 rects () 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
}
					

额外许可信息

On Embedded Linux, Windows CE and X11 platforms, parts of this class rely on code obtained under the following licenses:

Copyright (c) 1987 X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium.

Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.

保留所有权利

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

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

成员类型文档编制

enum QRegion:: RegionType

指定要创建的区域形状。

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

成员函数文档编制

QRegion:: QRegion ()

构造空区域。

另请参阅 isEmpty ().

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

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

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

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 (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:: QRegion (const QRect & r , RegionType t = Rectangle)

这是重载函数。

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

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

另请参阅 QRegion::RegionType .

QRect QRegion:: boundingRect () const

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

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

Returns true if the region contains the point p ;否则返回 false。

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

这是重载函数。

Returns true if the region overlaps the rectangle r ;否则返回 false。

Handle QRegion:: handle () const

Returns a platform-specific region handle. The Handle type is HRGN 在 Windows, Region on X11, and RgnHandle on Mac OS X. On Qt for Embedded Linux it is void * .

警告: This function is not portable.

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

Returns true if this region intersects with region ,否则返回 false。

该函数在 Qt 4.2 引入。

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

Returns true if this region intersects with rect ,否则返回 false。

该函数在 Qt 4.2 引入。

bool QRegion:: isEmpty () const

Returns true if the region is empty; otherwise returns false. An empty region is a region that contains no points.

范例:

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
					

int QRegion:: rectCount () const

返回矩形数,矩形的返回在 rects ().

该函数在 Qt 4.6 引入。

QVector < QRect > QRegion:: rects () const

返回组成区域的非重叠矩形数组。

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

另请参阅 setRects ().

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 ().

QRegion:: operator QVariant () const

返回区域按 QVariant

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

Returns true if this region is different from the other region; otherwise returns 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 )

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

Returns true if the region is equal to 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 运算符格式 .