 Home · All Classes · Modules

# QPolygon Class Reference[QtGui module]

The QPolygon class provides a vector of points using integer precision. More...

## Detailed Description

This class can be pickled.

The QPolygon class provides a vector of points using integer precision.

A QPolygon object is a QVector<QPoint>. The easiest way to add points to a QPolygon is to use QVector's streaming operator, as illustrated below:

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

In addition to the functions provided by QVector, QPolygon provides some point-specific functions.

Each point in a polygon can be retrieved by passing its index to the point() function. To populate the polygon, QPolygon provides the setPoint() function to set the point at a given index, the setPoints() function to set all the points in the polygon (resizing it to the given number of points), and the putPoints() function which copies a number of given points into the polygon from a specified index (resizing the polygon if necessary).

QPolygon provides the boundingRect() and translate() functions for geometry functions. Use the QMatrix.map() function for more general transformations of QPolygons.

The QPolygon class is implicitly shared.

## Method Documentation

### QPolygon.__init__ (self)

Constructs a polygon with no points.

### QPolygon.__init__ (self, QPolygona)

Constructs a polygon of the given size. Creates an empty polygon if size == 0.

### QPolygon.__init__ (self, list-of-QPoint v)

Constructs a copy of the given polygon.

### QPolygon.__init__ (self, QRectrectangle, bool closed = False)

Constructs a polygon containing the specified points.

### QPolygon.__init__ (self, int asize)

Constructs a polygon from the given rectangle. If closed is false, the polygon just contains the four points of the rectangle ordered clockwise, otherwise the polygon's fifth point is set to rectangle.topLeft().

Note that the bottom-right corner of the rectangle is located at (rectangle.x() + rectangle.width(), rectangle.y() + rectangle.height()).

### QRect QPolygon.boundingRect (self)

Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty.

### bool QPolygon.containsPoint (self, QPointpt, Qt.FillRulefillRule)

Returns true if the given point is inside the polygon according to the specified fillRule; otherwise returns false.

This function was introduced in Qt 4.3.

### QPolygon QPolygon.intersected (self, QPolygonr)

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

Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.

This function was introduced in Qt 4.3.

### QPoint QPolygon.point (self, int index)

Extracts the coordinates of the point at the given index to *x and *y (if they are valid pointers).

### QPolygon.putPoints (self, int index, int firstx, int firsty, ...)

Copies nPoints points from the variable argument list into this polygon from the given index.

The points are given as a sequence of integers, starting with firstx then firsty, and so on. The polygon is resized if index+nPoints exceeds its current size.

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

```         QPolygon polygon(1);
polygon = QPoint(4, 5);
polygon.putPoints(1, 2, 6,7, 8,9);
```

The following code has the same result, but here the putPoints() function overwrites rather than extends:

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

### QPolygon.setPoint (self, int index, QPointpt)

Sets the point at the given index to the point specified by (x, y).

### QPolygon.setPoint (self, int index, int x, int y)

Sets the point at the given index to the given point.

### QPolygon.setPoints (self, list-of-int points)

Resizes the polygon to nPoints and populates it with the given points.

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

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

### QPolygon.setPoints (self, int firstx, int firsty, ...)

Resizes the polygon to nPoints and populates it with the points specified by the variable argument list. The points are given as a sequence of integers, starting with firstx then firsty, and so on.

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

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

### QPolygon QPolygon.subtracted (self, QPolygonr)

Returns a polygon which is r subtracted from this polygon.

Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.

This function was introduced in Qt 4.3.

### QPolygon.swap (self, QPolygonother)

Swaps polygon other with this polygon. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

### QPolygon.translate (self, int dx, int dy)

Translates all points in the polygon by (dx, dy).

### QPolygon.translate (self, QPointoffset)

Translates all points in the polygon by the given offset.

### QPolygon QPolygon.translated (self, int dx, int dy)

Returns a copy of the polygon that is translated by (dx, dy).

This function was introduced in Qt 4.6.

### QPolygon QPolygon.translated (self, QPointoffset)

Returns a copy of the polygon that is translated by the given offset.

This function was introduced in Qt 4.6.

### QPolygon QPolygon.united (self, QPolygonr)

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

Set operations on polygons, will treat the polygons as areas, and implicitly close the polygon.

This function was introduced in Qt 4.3.

### QPolygon.__setitem__ (self, slice slice, QPolygonlist)

 PyQt 4.9.4 for Windows Copyright © Riverbank Computing Ltd and Nokia 2012 Qt 4.8.2