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  · 

QPoint Class Reference
[QtCore module]

The QPoint class defines a point in the plane using integer precision. More...

 #include <QPoint>

Public Functions

Related Non-Members

  • bool operator!= ( const QPoint & p1, const QPoint & p2 )
  • const QPoint operator* ( const QPoint & point, qreal factor )
  • const QPoint operator* ( qreal factor, const QPoint & point )
  • const QPoint operator+ ( const QPoint & p1, const QPoint & p2 )
  • const QPoint operator- ( const QPoint & p1, const QPoint & p2 )
  • const QPoint operator- ( const QPoint & point )
  • const QPoint operator/ ( const QPoint & point, qreal divisor )
  • QDataStream & operator<< ( QDataStream & stream, const QPoint & point )
  • bool operator== ( const QPoint & p1, const QPoint & p2 )
  • QDataStream & operator>> ( QDataStream & stream, QPoint & point )

Detailed Description

The QPoint class defines a point in the plane using integer precision.

A point is specified by a x coordinate and an y coordinate which can be accessed using the x() and y() functions. The isNull() function returns true if both x and y are set to 0. The coordinates can be set (or altered) using the setX() and setY() functions, or alternatively the rx() and ry() functions which return references to the coordinates (allowing direct manipulation).

Given a point p, the following statements are all equivalent:

 QPoint p;

 p.setX(p.x() + 1);
 p += QPoint(1, 0);
 p.rx()++;

A QPoint object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). A QPoint object can also be divided or multiplied by an int or a qreal.

In addition, the QPoint class provides the manhattanLength() function which gives an inexpensive approximation of the length of the QPoint object interpreted as a vector. Finally, QPoint objects can be streamed as well as compared.

See also QPointF and QPolygon.


Member Function Documentation

QPoint::QPoint ()

Constructs a null point, i.e. with coordinates (0, 0)

See also isNull().

QPoint::QPoint ( int x, int y )

Constructs a point with the given coordinates (x, y).

See also setX() and setY().

bool QPoint::isNull () const

Returns true if both the x and y coordinates are set to 0, otherwise returns false.

int QPoint::manhattanLength () const

Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" of the vector from the origin to the point. For example:

 QPoint oldPosition;

 MyWidget::mouseMoveEvent(QMouseEvent *event)
 {
     QPoint point = event->pos() - oldPosition;
     if (point.manhattanLength() > 3)
         // the mouse has moved more than 3 pixels since the oldPosition
 }

This is a useful, and quick to calculate, approximation to the true length:

 double trueLength = sqrt(pow(x(), 2) + pow(y(), 2));

The tradition of "Manhattan length" arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.

int & QPoint::rx ()

Returns a reference to the x coordinate of this point.

Using a reference makes it possible to directly manipulate x. For example:

 QPoint p(1, 2);
 p.rx()--;   // p becomes (0, 2)

See also x() and setX().

int & QPoint::ry ()

Returns a reference to the y coordinate of this point.

Using a reference makes it possible to directly manipulate y. For example:

 QPoint p(1, 2);
 p.ry()++;   // p becomes (1, 3)

See also y() and setY().

void QPoint::setX ( int x )

Sets the x coordinate of this point to the given x coordinate.

See also x() and setY().

void QPoint::setY ( int y )

Sets the y coordinate of this point to the given y coordinate.

See also y() and setX().

int QPoint::x () const

Returns the x coordinate of this point.

See also setX() and rx().

int QPoint::y () const

Returns the y coordinate of this point.

See also setY() and ry().

QPoint & QPoint::operator*= ( qreal factor )

Multiplies this point's coordinates by the given factor, and returns a reference to this point. For example:

 QPoint p(-1, 4);
 p *= 2.5;    // p becomes (-3, 10)

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also operator/=().

QPoint & QPoint::operator+= ( const QPoint & point )

Adds the given point to this point and returns a reference to this point. For example:

 QPoint p( 3, 7);
 QPoint q(-1, 4);
 p += q;    // p becomes (2, 11)

See also operator-=().

QPoint & QPoint::operator-= ( const QPoint & point )

Subtracts the given point from this point and returns a reference to this point. For example:

 QPoint p( 3, 7);
 QPoint q(-1, 4);
 p -= q;    // p becomes (4, 3)

See also operator+=().

QPoint & QPoint::operator/= ( qreal divisor )

Divides both x and y by the given divisor, and returns a reference to this point. For example:

 QPoint p(-3, 10);
 p /= 2.5;           // p becomes (-1, 4)

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also operator*=().


Related Non-Members

bool operator!= ( const QPoint & p1, const QPoint & p2 )

Returns true if p1 and p2 are not equal; otherwise returns false.

const QPoint operator* ( const QPoint & point, qreal factor )

Returns a copy of the given point multiplied by the given factor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also QPoint::operator*=().

const QPoint operator* ( qreal factor, const QPoint & point )

This is an overloaded member function, provided for convenience.

Returns a copy of the given point multiplied by the given factor.

const QPoint operator+ ( const QPoint & p1, const QPoint & p2 )

Returns a QPoint object that is the sum of the given points, p1 and p2; each component is added separately.

See also QPoint::operator+=().

const QPoint operator- ( const QPoint & p1, const QPoint & p2 )

Returns a QPoint object that is formed by subtracting p2 from p1; each component is subtracted separately.

See also QPoint::operator-=().

const QPoint operator- ( const QPoint & point )

This is an overloaded member function, provided for convenience.

Returns a QPoint object that is formed by changing the sign of both components of the given point.

Equivalent to QPoint(0,0) - point.

const QPoint operator/ ( const QPoint & point, qreal divisor )

Returns the QPoint formed by dividing both components of the given point by the given divisor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also QPoint::operator/=().

QDataStream & operator<< ( QDataStream & stream, const QPoint & point )

This is an overloaded member function, provided for convenience.

Writes the given point to the given stream and returns a reference to the stream.

See also Format of the QDataStream Operators.

bool operator== ( const QPoint & p1, const QPoint & p2 )

Returns true if p1 and p2 are equal; otherwise returns false.

QDataStream & operator>> ( QDataStream & stream, QPoint & point )

This is an overloaded member function, provided for convenience.

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

See also Format of the QDataStream Operators.

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 94
  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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  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. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 7
Page suivante

Le Qt Quarterly au hasard

Logo

Un plugin pour QImage

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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 qtextended4.4
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