Qt Toolkit - QRegion Class

# QRegion Class Reference

The QRegion class specifies a clip region for a painter. More...

`#include <qregion.h>`

List of all member functions.

## Public Members

- QRegion ()
- QRegion ( int x, int y, int w, int h, RegionType = Rectangle )
- QRegion ( const QRect &, RegionType = Rectangle )
- QRegion ( const QPointArray &, bool winding=FALSE )
- QRegion ( const QRegion & )
- QRegion ( const QBitmap & )
- ~QRegion ()
- QRegion& operator= ( const QRegion & )
- bool isNull () const
- bool isEmpty () const
- bool contains ( const QPoint & p ) const
- bool contains ( const QRect & r ) const
- void translate ( int dx, int dy )
- QRegion unite ( const QRegion & ) const
- QRegion intersect ( const QRegion & ) const
- QRegion subtract ( const QRegion & ) const
- QRegion eor ( const QRegion & ) const
- QRect boundingRect () const
- QArray<QRect> rects () const
- bool operator== ( const QRegion & ) const
- bool operator!= ( const QRegion & r ) const

## Related Functions

(Note that these are not member functions.)

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

## Detailed Description

The QRegion class specifies a clip region for a painter.

A region can be a rectangle, an ellipse, a polygon or a combination of these.

Regions are combined by creating a new region which is a union, intersection or difference between any two regions.

The region XOR operation is defined as:

        a XOR b = (a UNION b) - (a INTERSECTION b)

Example of using complex regions:

        void MyWidget::paintEvent( QPaintEvent * )
        {
            QPainter p;                             // our painter
            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.intersect( r2 );        // r3 = intersection
            p.begin( this );                        // start painting widget
            p.setClipRegion( r3 );                  // set clip region
            ...                                     // paint clipped graphics
            p.end();                                // painting done
        }

See also: QPainter::setClipRegion() and QPainter::setClipRect().

## Member Function Documentation

### QRegion::QRegion ()

Constructs an null region.

See also: isNull().

### QRegion::QRegion ( const QBitmap & bm )

Constructs a region from a bitmap.

The pixels in bm that are color1 will be part of the region as if each was a 1 by 1 rectangle.

### QRegion::QRegion ( const QPointArray & a, bool winding=FALSE )

Constructs a polygon region from the point array a.

If winding is TRUE, the polygon region uses the winding algorithm, otherwise the alternative (even-odd) algorithm will be used.

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

Constructs a rectangular or elliptic region.

Arguments:

- r is the region rectangle.
- t is the region type: QRegion::Rectangle (default) or QRegion::Ellipse.

### QRegion::QRegion ( const QRegion & r )

Constructs a region which is a shallow copy of r.

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

Constructs a rectangular or elliptic region.

x, y, w, and h specify the region rectangle. t is the region type: QRegion::Rectangle (default) or QRegion::Ellipse.

### QRegion::~QRegion ()

Destroys the region.

### QRect QRegion::boundingRect () const

Returns the bounding rectange of this region. An empty region gives a null rectangle.

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

Returns TRUE if the region contains the point p, or FALSE if p is outside the region.

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

Returns TRUE if the region contains the rectangle r, or FALSE if r is outside the region.

### QRegion QRegion::eor ( const QRegion & r ) const

Returns a region which is this region XOR r.

### QRegion QRegion::intersect ( const QRegion & r ) const

Returns a region which is the intersection of this region and r.

### bool QRegion::isEmpty () const

Returns TRUE if the region is empty, or FALSE if it is non-empty.

Example:

        QRegion r1( 10, 10, 20, 20 );
        QRegion r2( 40, 40, 20, 20 );
        QRegion r3;
        r1.isNull();                // FALSE
        r1.isEmpty();               // FALSE
        r3.isNull();                // TRUE
        r3.isEmpty();               // TRUE
        r3 = r1.intersect( r2 );    // r3 = intersection of r1 and r2
        r3.isNull();                // FALSE
        r3.isEmpty();               // TRUE
        r3 = r1.unite( r2 );        // r3 = union of r1 and r2
        r3.isNull();                // FALSE
        r3.isEmpty();               // FALSE

See also: isNull().

### bool QRegion::isNull () const

Returns TRUE if the region is a null region, otherwise FALSE.

A null region is a region that has not been initialized. The documentation for isEmpty() contains an example that shows how to use isNull() and isEmpty().

See also: isEmpty().

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

Returns TRUE if the region is different from r, or FALSE if the regions are equal.

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

Assigns a shallow copy of r to this region and returns a reference to the region.

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

Returns TRUE if the region is equal to r, or FALSE if the regions are different.

### QArray<QRect> QRegion::rects () const

Returns an array of the rectangles that make up the region. The rectangles are non-overlapping. The region is formed by the union of all these rectangles.

### QRegion QRegion::subtract ( const QRegion & r ) const

Returns a region which is r subtracted from this region.

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

Translates the region dx along the X axis and dy along the Y axis.

### QRegion QRegion::unite ( const QRegion & r ) const

Returns a region which is the union of this region and r.

## Related Functions

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

Writes a region to the stream and returns a reference to the stream.

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

Reads a region from the stream and returns a reference to the stream.

Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qregion.h: 1999/01/22
- qregion.cpp: 1998/07/03