Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QPolygon Class Reference
[QtGui module]

The QPolygon class provides a vector of points. More...

#include <QPolygon>

Inherits QVector<QPoint>.

Inherited by Q3PointArray.

Note: All the functions in this class are reentrant.

Public Functions

Additional Inherited Members


Detailed Description

The QPolygon class provides a vector of points.

A QPolygon is a QVector<QPoint>. It is implicitly shared. In addition to the functions provided by QVector, QPolygon provides some point-specific functions.

The easiest way to add points to a QPolygon is to use QVector's streaming operators, as illustrated below:

            QPolygon polygon;
            polygon << QPoint(10, 20) << QPoint(20, 30);

All other forms of manipulating a vector are available too, along with some compatibilty functions from Qt 3.

For geometry operations use boundingRect() and translate(). There is also the QMatrix::map() function for more general transformations of QPolygons.

Among others, QPolygon is used by QPainter::drawLineSegments(), QPainter::drawPolyline(), QPainter::drawPolygon() and QPainter::drawCubicBezier().

See also QPainter, QMatrix, QVector, and QPolygonF.


Member Function Documentation

QPolygon::QPolygon ()

Constructs an empty point array.

See also QVector::isEmpty().

QPolygon::QPolygon ( int size )

Constructs a point array with room for size points. Makes an empty array if size == 0.

See also QVector::isEmpty().

QPolygon::QPolygon ( const QPolygon & a )

Constructs a copy of the point array a.

QPolygon::QPolygon ( const QVector<QPoint> & pts )

Constructs a pointarray containing a copy of the points specified in pts.

QPolygon::QPolygon ( const QRect & r, bool closed = false )

Constructs a point array from the rectangle r.

If closed is false, then the point array just contains the following four points of the rectangle ordered clockwise. The bottom-right point is located at (r.x() + r.width(), r.y() + r.height()).

If closed is true, then a fifth point is set to r.topLeft().

QPolygon::~QPolygon ()

Destroys the point array.

QRect QPolygon::boundingRect () const

Returns the bounding rectangle of the points in the array, or QRect(0, 0, 0, 0) if the array is empty.

void QPolygon::point ( int index, int * x, int * y ) const

Reads the coordinates of the point at position index within the array and writes them into *x and *y if they are valid pointers.

See also setPoint().

QPoint QPolygon::point ( int index ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the point at position index within the array.

void QPolygon::putPoints ( int index, int nPoints, int firstx, int firsty, ... )

Copies nPoints points from the variable argument list into this point array from position index, and resizes the point array if index+nPoints exceeds the size of the array.

The example code creates an array with three points (4,5), (6,7) and (8,9), by expanding the array from 1 to 3 points:

            QPolygon polygon(1);
            polygon[0] = QPoint(4, 5);
            polygon.putPoints(1, 2, 6,7, 8,9); // index == 1, points == 2

This has the same result, but here putPoints overwrites rather than extends:

            QPolygon polygon(3);
            polygon.putPoints(0, 3, 4,5, 0,0, 8,9);
            polygon.putPoints(1, 1, 6,7);

The points are given as a sequence of integers, starting with firstx then firsty, and so on.

See also setPoints().

void QPolygon::putPoints ( int index, int nPoints, const QPolygon & from, int fromIndex = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version of the function copies nPoints from from into this array, starting at index in this array and fromIndex in from. fromIndex is 0 by default.

            QPolygon polygon1;
            polygon1.putPoints(0, 3, 1,2, 0,0, 5,6);
            // polygon1 is now the three-point array (1,2, 0,0, 5,6);

See also setPoints().

void QPolygon::setPoint ( int index, int x, int y )

Sets the point at position index in the array to (x, y).

See also point(), putPoints(), and setPoints().

void QPolygon::setPoint ( int i, const QPoint & p )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the point at array index i to p.

See also putPoints() and setPoints().

void QPolygon::setPoints ( int nPoints, const int * points )

Resizes the array to nPoints and sets the points in the array to the values taken from points.

The example code creates an array with two points (10, 20) and (30, 40):

            static const int points[] = { 10, 20, 30, 40 };
            QPolygon polygon;
            polygon.setPoints(2, points);

See also resize(), setPoint(), and putPoints().

void QPolygon::setPoints ( int nPoints, int firstx, int firsty, ... )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Resizes the array to nPoints and sets the points in the array to the values taken from the variable argument list.

The example code creates an array with two points (10, 20) and (30, 40):

            QPolygon polygon;
            polygon.setPoints(2, 10, 20, 30, 40);

The points are given as a sequence of integers, starting with firstx then firsty, and so on.

See also resize(), putPoints(), and setPoint().

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

Translate all points in the array by (dx, dy).

void QPolygon::translate ( const QPoint & offset )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Translate all points in the array by offset.

QPolygon::operator QVariant () const

Returns the polygon as a QVariant


Copyright © 2005 Trolltech Trademarks
Qt 4.1.0
Hosted by uCoz