QPolygon 類

QPolygon 類提供使用整數精度的點列錶。 更多...

頭: #include <QPolygon>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
繼承: QList

注意: 此類的所有函數 可重入 .

公共函數

QPolygon ()
QPolygon (const QList<QPoint> & points )
QPolygon (const QRect & rectangle , bool closed = false)
QRect boundingRect () const
bool containsPoint (const QPoint & point , Qt::FillRule fillRule ) const
QPolygon intersected (const QPolygon & r ) const
bool intersects (const QPolygon & p ) const
void point (int index , int * x , int * y ) const
QPoint point (int index ) const
void putPoints (int index , int nPoints , int firstx , int firsty , ...)
void putPoints (int index , int nPoints , const QPolygon & fromPolygon , int fromIndex = 0)
void setPoint (int index , int x , int y )
void setPoint (int index , const QPoint & point )
void setPoints (int nPoints , const int * points )
void setPoints (int nPoints , int firstx , int firsty , ...)
QPolygon subtracted (const QPolygon & r ) const
void swap (QPolygon & other )
(從 6.4 起) QPolygonF toPolygonF () const
void translate (int dx , int dy )
void translate (const QPoint & offset )
QPolygon translated (int dx , int dy ) const
QPolygon translated (const QPoint & offset ) const
QPolygon united (const QPolygon & r ) const
QVariant operator QVariant () const
QDataStream & operator<< (QDataStream & stream , const QPolygon & polygon )
QDataStream & operator>> (QDataStream & stream , QPolygon & polygon )

詳細描述

QPolygon 對象是 QList < QPoint >. The easiest way to add points to a QPolygon is to use QList 's streaming operator, as illustrated below:

QPolygon polygon;
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 () 和 translate () functions for geometry functions. Use the QTransform::map () function for more general transformations of QPolygons.

QPolygon 類是 隱式共享 .

另請參閱 QList , QPolygonF ,和 QLine .

成員函數文檔編製

[constexpr noexcept] QPolygon:: QPolygon ()

Constructs a polygon with no points.

另請參閱 QList::isEmpty ().

QPolygon:: QPolygon (const QList < QPoint > & points )

Constructs a polygon containing the specified points .

另請參閱 setPoints ().

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

Constructs a polygon from the given rectangle 。若 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()).

另請參閱 setPoints ().

QRect QPolygon:: boundingRect () const

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

另請參閱 QList::isEmpty ().

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

返迴 true 若給定 point is inside the polygon according to the specified fillRule ;否則返迴 false .

QPolygon QPolygon:: intersected (const QPolygon & r ) const

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.

另請參閱 intersects ().

bool QPolygon:: intersects (const QPolygon & p ) const

返迴 true if the current polygon intersects at any point the given polygon p 。也返迴 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.

另請參閱 intersected ().

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

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

另請參閱 setPoint ().

QPoint QPolygon:: point ( int index ) const

Returns the point at the given index .

這是重載函數。

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

拷貝 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[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);
					

另請參閱 setPoints ().

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

拷貝 nPoints points from the given fromIndex ( 0 by default) in fromPolygon into this polygon, starting at the specified index 。例如:

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 given index to the point specified by ( x , y ).

另請參閱 point (), putPoints (),和 setPoints ().

void QPolygon:: setPoint ( int index , const QPoint & point )

Sets the point at the given index 到給定 point .

這是重載函數。

void QPolygon:: setPoints ( int nPoints , const 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);
					

另請參閱 setPoint () 和 putPoints ().

void QPolygon:: setPoints ( int nPoints , 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 (const QPolygon & r ) const

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.

[noexcept] void QPolygon:: swap ( QPolygon & other )

Swaps this polygon with other 。此操作很快且從不失敗。

[since 6.4] QPolygonF QPolygon:: toPolygonF () const

Returns this polygon as a polygon with floating point accuracy.

該函數在 Qt 6.4 引入。

另請參閱 QPolygonF::toPolygon ().

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

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

另請參閱 translated ().

void QPolygon:: translate (const QPoint & offset )

Translates all points in the polygon by the given offset .

這是重載函數。

另請參閱 translated ().

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

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

另請參閱 translate ().

QPolygon QPolygon:: translated (const QPoint & offset ) const

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

這是重載函數。

另請參閱 translate ().

QPolygon QPolygon:: united (const QPolygon & r ) const

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.

另請參閱 intersected () 和 subtracted ().

QVariant QPolygon:: operator QVariant () const

Returns the polygon as a QVariant

相關非成員

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

寫入給定 polygon 到給定 stream ,並返迴流引用。

另請參閱 序列化 Qt 數據類型 .

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

Reads a polygon from the given stream 進給定 polygon ,並返迴流引用。

另請參閱 序列化 Qt 數據類型 .