class QPolygon

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

Synopsis

Methods

Static functions

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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

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

In addition to the functions provided by QList, 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 map() function for more general transformations of QPolygons.

The QPolygon class is implicitly shared.

See also

QPolygonF QLine

__init__()

Constructs a polygon with no points.

See also

isEmpty()

__init__(v)
Parameters:

v – .list of QPoint

Constructs a polygon containing the specified points.

See also

setPoints()

__init__(r[, closed=false])
Parameters:
  • rQRect

  • closed – bool

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

See also

setPoints()

__reduce__()
Return type:

str

append(arg__1)
Parameters:

arg__1QPoint

append(l)
Parameters:

l – .list of QPoint

at(i)
Parameters:

i – int

Return type:

QPoint

back()
Return type:

QPoint

boundingRect()
Return type:

QRect

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

See also

isEmpty()

capacity()
Return type:

int

clear()
constData()
Return type:

QPoint

constFirst()
Return type:

QPoint

constLast()
Return type:

QPoint

containsPoint(pt, fillRule)
Parameters:
Return type:

bool

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

count()
Return type:

int

data()
Return type:

QPoint

empty()
Return type:

bool

first()
Return type:

QPoint

first(n)
Parameters:

n – int

Return type:

.list of QPoint

static fromList(list)
Parameters:

list – .list of QPoint

Return type:

.list of QPoint

static fromVector(vector)
Parameters:

vector – .list of QPoint

Return type:

.list of QPoint

front()
Return type:

QPoint

insert(arg__1, arg__2)
Parameters:
  • arg__1 – int

  • arg__2QPoint

intersected(r)
Parameters:

rQPolygon

Return type:

QPolygon

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.

See also

intersects()

intersects(r)
Parameters:

rQPolygon

Return type:

bool

Returns true if the current polygon intersects at any point the given polygon p. Also returns true if the current polygon contains or is contained by any part of p.

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

See also

intersected()

isEmpty()
Return type:

bool

isSharedWith(other)
Parameters:

other – .list of QPoint

Return type:

bool

last()
Return type:

QPoint

last(n)
Parameters:

n – int

Return type:

.list of QPoint

length()
Return type:

int

static maxSize()
Return type:

int

max_size()
Return type:

int

mid(pos[, len=-1])
Parameters:
  • pos – int

  • len – int

Return type:

.list of QPoint

move(from, to)
Parameters:
  • from – int

  • to – int

__ne__(arg__1)
Parameters:

arg__1QPolygon

Return type:

bool

__mul__(m)
Parameters:

mQTransform

Return type:

QPolygon

__add__(l)
Parameters:

l – .list of QPoint

Return type:

.list of QPoint

__lshift__(arg__1)
Parameters:

arg__1 – .list of QPoint

__lshift__(arg__1)
Parameters:

arg__1QPoint

__eq__(arg__1)
Parameters:

arg__1QPolygon

Return type:

bool

operator(i)
Parameters:

i – int

Return type:

QPoint

pop_back()
pop_front()
prepend(arg__1)
Parameters:

arg__1QPoint

push_back(arg__1)
Parameters:

arg__1QPoint

push_front(arg__1)
Parameters:

arg__1QPoint

remove(i[, n=1])
Parameters:
  • i – int

  • n – int

removeAll(arg__1)
Parameters:

arg__1QPoint

removeAt(i)
Parameters:

i – int

removeFirst()
removeLast()
removeOne(arg__1)
Parameters:

arg__1QPoint

reserve(size)
Parameters:

size – int

resize(size)
Parameters:

size – int

resizeForOverwrite(size)
Parameters:

size – int

shrink_to_fit()
size()
Return type:

int

sliced(pos)
Parameters:

pos – int

Return type:

.list of QPoint

sliced(pos, n)
Parameters:
  • pos – int

  • n – int

Return type:

.list of QPoint

squeeze()
subtracted(r)
Parameters:

rQPolygon

Return type:

QPolygon

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.

swap(other)
Parameters:

otherQPolygon

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

swapItemsAt(i, j)
Parameters:
  • i – int

  • j – int

takeAt(i)
Parameters:

i – int

Return type:

QPoint

toList()
Return type:

.list of QPoint

toPolygonF()
Return type:

QPolygonF

Returns this polygon as a polygon with floating point accuracy.

See also

toPolygon()

toVector()
Return type:

.list of QPoint

translate(offset)
Parameters:

offsetQPoint

This is an overloaded function.

Translates all points in the polygon by the given offset.

See also

translated()

translate(dx, dy)
Parameters:
  • dx – int

  • dy – int

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

See also

translated()

translated(offset)
Parameters:

offsetQPoint

Return type:

QPolygon

This is an overloaded function.

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

See also

translate()

translated(dx, dy)
Parameters:
  • dx – int

  • dy – int

Return type:

QPolygon

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

See also

translate()

united(r)
Parameters:

rQPolygon

Return type:

QPolygon

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.

value(i)
Parameters:

i – int

Return type:

QPoint