QPoint Class Reference


The QPoint class defines a point in the plane. (details) (complete member list)

#include <qpoint.h>

Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

The QPoint class defines a point in the plane.

A point is specified by an x coordinate and a y coordinate.

The coordinate type is QCOORD (defined as short). The minimum value of QCOORD is -32768 and the maximum value is 32767.

We have defined many operator functions that makes arithmetic on points simple and intuitive:

  QPoint p(  1, 2 );
  QPoint q( -8, 5 );
  QPoint r(  9, 7 );
  QPoint x = 2*p + (q-r)*5.5 - (r+p/1.5);

See also: QSize and QRect.


Member Function Documentation

QPoint::QPoint ()

Constructs a point with undefined x and y values.

QPoint::QPoint (QCOORD xpos, QCOORD ypos)

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

bool QPoint::isNull () const

Returns TRUE if both the x value and the y value are 0.

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

Multiplies both x and y with c, and return a reference to this point.

  QPoint p( -1, 4 );
  p *= 2;                       // p becomes (-2,8)

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

Multiplies both x and y with c, and return a reference to this point.

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

Notice that the result is truncated.

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

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

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

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

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

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

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

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

The division will not be performed if c is 0.

  QPoint p( -2, 8 );
  p /= 2;                       // p becomes (-1,4)

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

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

The division will not be performed if c is 0.

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

Notice that the result is truncated.

QCOORD & QPoint::rx ()

Returns a reference to the x coordinate of the point.

Using a reference makes it possible to directly manipulate x:

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

See also: ry().

QCOORD & QPoint::ry ()

Returns a reference to the y coordinate of the point.

Using a reference makes it possible to directly manipulate y:

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

See also: rx().

void QPoint::setX (QCOORD x)

Sets the x coordinate of the point to x.

See also: setY().

void QPoint::setY (QCOORD y)

Sets the y coordinate of the point to y.

See also: setX().

QCOORD QPoint::x () const

Returns the x coordinate of the point.

See also: y().

QCOORD QPoint::y () const

Returns the y coordinate of the point.

See also: x().


Related Functions

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

Returns TRUE if p1 and p2 are equal, or FALSE if they are different.

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

Returns TRUE if p1 and p2 are different, or FALSE if they are equal.

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

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

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

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

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

Multiplies both of p's components by c and returns the result.

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

Multiplies both of p's components by c and returns the result.

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

Multiplies both of p's components by c and returns the result.

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

Multiplies both of p's components by c and returns the result.

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

Divides both of p's components by c and returns the result.

This function returns p if c is 0.

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

Divides both of p's components by c and returns the result.

This function returns p if c is 0.

Notice that the result is truncated.

QPoint operator- (const QPoint &p)

Returns p where x and y have opposite signs.

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

Writes a QPoint to the stream.

The output format is two INT16 (first x, then y).

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

Reads a QPoint from the stream.


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 16:17, 1995/06/30 by the webmaster at Troll Tech