Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QPolygon Class

TheQPolygon class provides a vector of points using integer precision.More...

Header:#include <QPolygon>
Inherits:QVector<QPoint>
Inherited By:

Q3PointArray

Note: All functions in this class arereentrant.

Public Functions

QPolygon()
QPolygon(int size)
QPolygon(const QPolygon & polygon)
QPolygon(const QVector<QPoint> & points)
QPolygon(const QRect & rectangle, bool closed = false)
~QPolygon()
QRectboundingRect() const
boolcontainsPoint(const QPoint & point, Qt::FillRule fillRule) const
QPolygonintersected(const QPolygon & r) const
voidpoint(int index, int * x, int * y) const
QPointpoint(int index) const
voidputPoints(int index, int nPoints, int firstx, int firsty, ...)
voidputPoints(int index, int nPoints, const QPolygon & fromPolygon, int fromIndex = 0)
voidsetPoint(int index, int x, int y)
voidsetPoint(int index, const QPoint & point)
voidsetPoints(int nPoints, const int * points)
voidsetPoints(int nPoints, int firstx, int firsty, ...)
QPolygonsubtracted(const QPolygon & r) const
voidswap(QPolygon & other)
voidtranslate(int dx, int dy)
voidtranslate(const QPoint & offset)
QPolygontranslated(int dx, int dy) const
QPolygontranslated(const QPoint & offset) const
QPolygonunited(const QPolygon & r) const
operator QVariant() const
  • 66 public functions inherited fromQVector

Related Non-Members

QDataStream &operator<<(QDataStream & stream, const QPolygon & polygon)
QDataStream &operator>>(QDataStream & stream, QPolygon & polygon)

Additional Inherited Members

  • 2 static public members inherited fromQVector

Detailed Description

TheQPolygon class provides a vector of points using integer precision.

AQPolygon object is aQVector<QPoint>. The easiest way to add points to aQPolygon is to useQVector's streaming operator, as illustrated below:

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

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

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

QPolygon provides theboundingRect() andtranslate() functions for geometry functions. Use theQMatrix::map() function for more general transformations of QPolygons.

TheQPolygon class isimplicitly shared.

See alsoQVector,QPolygonF, andQLine.

Member Function Documentation

QPolygon::QPolygon()

Constructs a polygon with no points.

See alsoQVector::isEmpty().

QPolygon::QPolygon(int size)

Constructs a polygon of the givensize. Creates an empty polygon ifsize == 0.

See alsoQVector::isEmpty().

QPolygon::QPolygon(constQPolygon & polygon)

Constructs a copy of the givenpolygon.

See alsosetPoints().

QPolygon::QPolygon(constQVector<QPoint> & points)

Constructs a polygon containing the specifiedpoints.

See alsosetPoints().

QPolygon::QPolygon(constQRect & rectangle,bool closed = false)

Constructs a polygon from the givenrectangle. Ifclosed is false, the polygon just contains the four points of the rectangle ordered clockwise, otherwise the polygon's fifth point is set torectangle.topLeft().

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

See alsosetPoints().

QPolygon::~QPolygon()

Destroys the polygon.

QRect QPolygon::boundingRect() const

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

See alsoQVector::isEmpty().

bool QPolygon::containsPoint(constQPoint & point,Qt::FillRule fillRule) const

Returns true if the givenpoint is inside the polygon according to the specifiedfillRule; otherwise returns false.

This function was introduced in Qt 4.3.

QPolygon QPolygon::intersected(constQPolygon & r) const

Returns a polygon which is the intersection of this polygon andr.

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.

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

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

See alsosetPoint().

QPoint QPolygon::point(int index) const

This is an overloaded function.

Returns the point at the givenindex.

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

CopiesnPoints points from the variable argument list into this polygon from the givenindex.

The points are given as a sequence of integers, starting withfirstx thenfirsty, and so on. The polygon is resized ifindex+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[0]=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);

See alsosetPoints().

void QPolygon::putPoints(int index,int nPoints, constQPolygon & fromPolygon,int fromIndex = 0)

This is an overloaded function.

CopiesnPoints points from the givenfromIndex ( 0 by default) infromPolygon into this polygon, starting at the specifiedindex. For example:

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

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

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

See alsopoint(),putPoints(), andsetPoints().

void QPolygon::setPoint(int index, constQPoint & point)

This is an overloaded function.

Sets the point at the givenindex to the givenpoint.

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

Resizes the polygon tonPoints and populates it with the givenpoints.

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

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

See alsosetPoint() andputPoints().

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

This is an overloaded function.

Resizes the polygon tonPoints and populates it with the points specified by the variable argument list. The points are given as a sequence of integers, starting withfirstx thenfirsty, 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(constQPolygon & r) const

Returns a polygon which isr 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.

void QPolygon::swap(QPolygon & other)

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

This function was introduced in Qt 4.8.

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

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

See alsotranslated().

void QPolygon::translate(constQPoint & offset)

This is an overloaded function.

Translates all points in the polygon by the givenoffset.

See alsotranslated().

QPolygon QPolygon::translated(int dx,int dy) const

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

This function was introduced in Qt 4.6.

See alsotranslate().

QPolygon QPolygon::translated(constQPoint & offset) const

This is an overloaded function.

Returns a copy of the polygon that is translated by the givenoffset.

This function was introduced in Qt 4.6.

See alsotranslate().

QPolygon QPolygon::united(constQPolygon & r) const

Returns a polygon which is the union of this polygon andr.

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

This function was introduced in Qt 4.3.

See alsointersected() andsubtracted().

QPolygon::operator QVariant() const

Returns the polygon as aQVariant

Related Non-Members

QDataStream &operator<<(QDataStream & stream, constQPolygon & polygon)

Writes the givenpolygon to the givenstream, and returns a reference to the stream.

This function was introduced in Qt 4.4.

See alsoSerializing Qt Data Types.

QDataStream &operator>>(QDataStream & stream,QPolygon & polygon)

Reads a polygon from the givenstream into the givenpolygon, and returns a reference to the stream.

This function was introduced in Qt 4.4.

See alsoSerializing Qt Data Types.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp