Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QPolygon Class Reference

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

 #include <QPolygon>

Inherits: QVector<QPoint>.

Inherited by: Q3PointArray.

Note: All functions in this class are reentrant.

Public Functions

QPolygon ()
QPolygon ( int size )
QPolygon ( const QPolygon & polygon )
QPolygon ( const QVector<QPoint> & points )
QPolygon ( const QRect & rectangle, bool closed = false )
~QPolygon ()
QRect boundingRect () const
bool containsPoint ( const QPoint & point, Qt::FillRule fillRule ) const
QPolygon intersected ( const QPolygon & r ) 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 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
operator QVariant () const
  • 64 public functions inherited from QVector

Related Non-Members

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

Additional Inherited Members

  • 2 static public members inherited from QVector

Detailed Description

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.

See also QVector, QPolygonF, and QLine.

Member Function Documentation

QPolygon::QPolygon ()

Constructs a polygon with no points.

See also QVector::isEmpty().

QPolygon::QPolygon ( int size )

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

See also QVector::isEmpty().

QPolygon::QPolygon ( const QPolygon & polygon )

Constructs a copy of the given polygon.

See also setPoints().

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

Constructs a polygon containing the specified points.

See also setPoints().

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

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

QPolygon::~QPolygon ()

Destroys the polygon.

QRect QPolygon::boundingRect () const

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

See also QVector::isEmpty().

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

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

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 given index to *x and *y (if they are valid pointers).

See also setPoint().

QPoint QPolygon::point ( int index ) const

This is an overloaded function.

Returns the point at the given index.

void QPolygon::putPoints ( int index, int nPoints, 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[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 also setPoints().

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

This is an overloaded function.

Copies nPoints points from the given fromIndex ( 0 by default) in fromPolygon into this polygon, starting at the specified index. 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 given index to the point specified by (x, y).

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

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

This is an overloaded function.

Sets the point at the given index to the given 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);

See also setPoint() and putPoints().

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

This is an overloaded function.

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.

This function was introduced in Qt 4.3.

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

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

See also translated().

void QPolygon::translate ( const QPoint & offset )

This is an overloaded function.

Translates all points in the polygon by the given offset.

See also translated().

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

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

This is an overloaded function.

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

This function was introduced in Qt 4.6.

See also 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.

This function was introduced in Qt 4.3.

See also intersected() and subtracted().

QPolygon::operator QVariant () const

Returns the polygon as a QVariant

Related Non-Members

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

Writes the given polygon to the given stream, and returns a reference to the stream.

This function was introduced in Qt 4.4.

See also Serializing Qt Data Types.

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

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

This function was introduced in Qt 4.4.

See also Serializing Qt Data Types.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 68
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web