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  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QPoint Class Reference
[QtCore module]

The QPoint class defines a point in the plane. More...

#include <QPoint>

Public Functions

Related Non-Members

  • bool operator!= ( const QPoint & p1, const QPoint & p2 )
  • const QPoint operator* ( const QPoint & p, qreal c )
  • const QPoint operator* ( qreal c, const QPoint & p )
  • const QPoint operator+ ( const QPoint & p1, const QPoint & p2 )
  • const QPoint operator- ( const QPoint & p1, const QPoint & p2 )
  • const QPoint operator- ( const QPoint & p )
  • const QPoint operator/ ( const QPoint & p, qreal c )
  • QDataStream & operator<< ( QDataStream & s, const QPoint & p )
  • bool operator== ( const QPoint & p1, const QPoint & p2 )
  • QDataStream & operator>> ( QDataStream & s, QPoint & p )

Detailed Description

The QPoint class defines a point in the plane.

A point is specified by an x coordinate and a y coordinate. The coordinates are specified using integer numbers. QPointF provides points with floating point accuracy.

The coordinates are accessed by the functions x() and y(); they can be set by setX() and setY() or by the reference functions rx() and ry().

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

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

A QPoint can also be used as a vector. Addition and subtraction of QPoints are defined as for vectors (each component is added separately). You can divide or multiply a QPoint by an int or a qreal. The function manhattanLength() gives an inexpensive approximation of the length of the QPoint interpreted as a vector.

Example:

    //QPoint oldPos is defined somewhere else
    MyWidget::mouseMoveEvent(QMouseEvent *e)
    {
        QPoint vector = e->pos() - oldPos;
        if (vector.manhattanLength() > 3)
        ... //mouse has moved more than 3 pixels since oldPos
    }

QPoints can be compared for equality or inequality, and they can be written to and read from a QStream.

See also QPolygon, QSize, QRect, and QPointF.


Member Function Documentation

QPoint::QPoint ()

Constructs a point with coordinates (0, 0) (isNull() returns true).

QPoint::QPoint ( int xpos, int ypos )

Constructs a point with x value xpos and y value ypos.

bool QPoint::isNull () const

Returns true if both the x value and the y value are 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. The tradition arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.

This is a useful, and quick to calculate, approximation to the true length: sqrt(pow(x(),2)+pow(y(),2)).

int & QPoint::rx ()

Returns a reference to the x coordinate of the point.

Using a reference makes it possible to directly manipulate x.

Example:

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

See also ry() and setX().

int & QPoint::ry ()

Returns a reference to the y coordinate of the point.

Using a reference makes it possible to directly manipulate y.

Example:

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

See also rx() and setY().

void QPoint::setX ( int x )

Sets the x coordinate of the point to x.

See also x() and setY().

void QPoint::setY ( int y )

Sets the y coordinate of the point to y.

See also y() and setX().

int QPoint::x () const

Returns the x coordinate of the point.

See also setX() and y().

int QPoint::y () const

Returns the y coordinate of the point.

See also setY() and x().

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

Multiplies this point's x and y by c, and returns a reference to this point.

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.

See also QPointF.

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

Adds point p to this point and returns a reference to this point.

Example:

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

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

Subtracts point p from this point and returns a reference to this point.

Example:

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

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

Divides both x and y by c, and returns a reference to this point.

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.

See also QPointF.


Related Non-Members

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

const QPoint operator* ( const QPoint & p, qreal c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the QPoint formed by multiplying both components of p by c.

Note that the result is rounded to the nearest integer as points are held as integers.

See also QPointF.

const QPoint operator* ( qreal c, const QPoint & p )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the QPoint formed by multiplying both components of p by c.

Note that the result is rounded to the nearest integer as points are held as integers.

See also QPointF.

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the sum of p1 and p2; each component is added separately.

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

Returns p2 subtracted from p1; each component is subtracted separately.

const QPoint operator- ( const QPoint & p )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the QPoint formed by changing the sign of both components of p, equivalent to QPoint(0,0) - p.

const QPoint operator/ ( const QPoint & p, qreal c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the QPoint formed by dividing both components of p by c.

Note that the result is rounded to the nearest integer as points are held as integers.

See also QPointF.

QDataStream & operator<< ( QDataStream & s, const QPoint & p )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Writes point p to the stream s and returns a reference to the stream.

See also Format of the QDataStream operators.

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

QDataStream & operator>> ( QDataStream & s, QPoint & p )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reads a QPoint from the stream s into point p 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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 47
  4. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  5. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 12
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le blog Digia au hasard

Logo

Une nouvelle ère d'IHM 3D pour les automobiles

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