QtBase  v6.3.1
Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QPoint Class Reference

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

#include <qpoint.h>

Public Member Functions

constexpr QPoint () noexcept
 
constexpr QPoint (int xpos, int ypos) noexcept
 
constexpr bool isNull () const noexcept
 
constexpr int x () const noexcept
 
constexpr int y () const noexcept
 
constexpr void setX (int x) noexcept
 
constexpr void setY (int y) noexcept
 
constexpr int manhattanLength () const
 
constexpr QPoint transposed () const noexcept
 
constexpr int & rx () noexcept
 
constexpr int & ry () noexcept
 
constexpr QPointoperator+= (const QPoint &p)
 
constexpr QPointoperator-= (const QPoint &p)
 
constexpr QPointoperator*= (float factor)
 
constexpr QPointoperator*= (double factor)
 
constexpr QPointoperator*= (int factor)
 
constexpr QPointoperator/= (qreal divisor)
 

Static Public Member Functions

constexpr static int dotProduct (const QPoint &p1, const QPoint &p2)
 

Friends

class QTransform
 
constexpr friend bool operator== (const QPoint &p1, const QPoint &p2) noexcept
 
constexpr friend bool operator!= (const QPoint &p1, const QPoint &p2) noexcept
 
constexpr friend QPoint operator+ (const QPoint &p1, const QPoint &p2) noexcept
 
constexpr friend QPoint operator- (const QPoint &p1, const QPoint &p2) noexcept
 
constexpr friend QPoint operator* (const QPoint &p, float factor)
 
constexpr friend QPoint operator* (const QPoint &p, double factor)
 
constexpr friend QPoint operator* (const QPoint &p, int factor) noexcept
 
constexpr friend QPoint operator* (float factor, const QPoint &p)
 
constexpr friend QPoint operator* (double factor, const QPoint &p)
 
constexpr friend QPoint operator* (int factor, const QPoint &p) noexcept
 
constexpr friend QPoint operator+ (const QPoint &p) noexcept
 
constexpr friend QPoint operator- (const QPoint &p) noexcept
 
constexpr friend QPoint operator/ (const QPoint &p, qreal c)
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QPoint &point)
 
QDataStreamoperator>> (QDataStream &stream, QPoint &point)
 

Detailed Description

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

\inmodule QtCore

\reentrant

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:

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, QPolygon

Definition at line 51 of file qpoint.h.

Constructor & Destructor Documentation

◆ QPoint() [1/2]

constexpr QPoint::QPoint ( )
inlineconstexprnoexcept

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

See also
isNull()

Definition at line 146 of file qpoint.h.

Here is the caller graph for this function:

◆ QPoint() [2/2]

constexpr QPoint::QPoint ( int  xpos,
int  ypos 
)
inlineconstexprnoexcept

Constructs a point with the given coordinates (xpos, ypos).

See also
setX(), setY()

Definition at line 148 of file qpoint.h.

Member Function Documentation

◆ dotProduct()

static int QPoint::dotProduct ( const QPoint p1,
const QPoint p2 
)
inlinestaticconstexpr
Since
5.1

Returns the dot product of p1 and p2.

Definition at line 80 of file qpoint.h.

◆ isNull()

constexpr bool QPoint::isNull ( ) const
inlineconstexprnoexcept

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

Definition at line 150 of file qpoint.h.

Here is the caller graph for this function:

◆ manhattanLength()

constexpr int QPoint::manhattanLength ( ) const
inlineconstexpr

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:

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

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.

Definition at line 175 of file qpoint.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*=() [1/3]

constexpr QPoint & QPoint::operator*= ( double  factor)
inlineconstexpr

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

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/=()

Definition at line 211 of file qpoint.h.

Here is the call graph for this function:

◆ operator*=() [2/3]

constexpr QPoint & QPoint::operator*= ( float  factor)
inlineconstexpr

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

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/=()

Definition at line 204 of file qpoint.h.

Here is the call graph for this function:

◆ operator*=() [3/3]

constexpr QPoint & QPoint::operator*= ( int  factor)
inlineconstexpr

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

See also
operator/=()

Definition at line 218 of file qpoint.h.

◆ operator+=()

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

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

See also
operator-=()

Definition at line 190 of file qpoint.h.

◆ operator-=()

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

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

See also
operator+=()

Definition at line 197 of file qpoint.h.

◆ operator/=()

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

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*=()

Definition at line 225 of file qpoint.h.

Here is the call graph for this function:

◆ rx()

constexpr int & QPoint::rx ( )
inlineconstexprnoexcept

Returns a reference to the x coordinate of this point.

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

See also
x(), setX()

Definition at line 180 of file qpoint.h.

Here is the caller graph for this function:

◆ ry()

constexpr int & QPoint::ry ( )
inlineconstexprnoexcept

Returns a reference to the y coordinate of this point.

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

See also
y(), setY()

Definition at line 185 of file qpoint.h.

Here is the caller graph for this function:

◆ setX()

constexpr void QPoint::setX ( int  x)
inlineconstexprnoexcept

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

See also
x(), setY()

Definition at line 165 of file qpoint.h.

Here is the caller graph for this function:

◆ setY()

constexpr void QPoint::setY ( int  y)
inlineconstexprnoexcept

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

See also
y(), setX()

Definition at line 170 of file qpoint.h.

Here is the caller graph for this function:

◆ transposed()

QPoint::transposed ( ) const
inlineconstexprnoexcept
Since
5.14

Returns a point with x and y coordinates exchanged:

QPoint{1, 2}.transposed() // {2, 1}
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
constexpr QPoint transposed() const noexcept
Definition: qpoint.h:66
See also
x(), y(), setX(), setY()

Definition at line 66 of file qpoint.h.

Here is the caller graph for this function:

◆ x()

constexpr int QPoint::x ( ) const
inlineconstexprnoexcept

Returns the x coordinate of this point.

See also
setX(), rx()

Definition at line 155 of file qpoint.h.

Here is the caller graph for this function:

◆ y()

constexpr int QPoint::y ( ) const
inlineconstexprnoexcept

Returns the y coordinate of this point.

See also
setY(), ry()

Definition at line 160 of file qpoint.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool QPoint::operator!= ( const QPoint p1,
const QPoint p2 
)
friend

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

Definition at line 85 of file qpoint.h.

◆ operator* [1/6]

QPoint QPoint::operator* ( const QPoint point,
double  factor 
)
friend

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*=()

Definition at line 93 of file qpoint.h.

◆ operator* [2/6]

QPoint QPoint::operator* ( const QPoint point,
float  factor 
)
friend

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*=()

Definition at line 91 of file qpoint.h.

◆ operator* [3/6]

QPoint QPoint::operator* ( const QPoint point,
int  factor 
)
friend

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

See also
QPoint::operator*=()

Definition at line 95 of file qpoint.h.

◆ operator* [4/6]

QPoint QPoint::operator* ( double  factor,
const QPoint point 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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*=()

Definition at line 99 of file qpoint.h.

◆ operator* [5/6]

QPoint QPoint::operator* ( float  factor,
const QPoint point 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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*=()

Definition at line 97 of file qpoint.h.

◆ operator* [6/6]

QPoint QPoint::operator* ( int  factor,
const QPoint point 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

See also
QPoint::operator*=()

Definition at line 101 of file qpoint.h.

◆ operator+ [1/2]

QPoint QPoint::operator+ ( const QPoint point)
friend
Since
5.0

Returns point unmodified.

Definition at line 103 of file qpoint.h.

◆ operator+ [2/2]

QPoint QPoint::operator+ ( const QPoint p1,
const QPoint p2 
)
friend

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

See also
QPoint::operator+=()

Definition at line 87 of file qpoint.h.

◆ operator- [1/2]

QPoint QPoint::operator- ( const QPoint point)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Equivalent to {QPoint(0,0) - point}.

Definition at line 105 of file qpoint.h.

◆ operator- [2/2]

Point QPoint::operator- ( const QPoint p1,
const QPoint p2 
)
friend

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

See also
QPoint::operator-=()

Definition at line 89 of file qpoint.h.

◆ operator/

const QPoint QPoint::operator/ ( const QPoint point,
qreal  divisor 
)
friend

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/=()

Definition at line 107 of file qpoint.h.

◆ operator<<()

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

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

See also
{Serializing Qt Data Types}

Definition at line 398 of file qpoint.cpp.

◆ operator==

bool QPoint::operator== ( const QPoint p1,
const QPoint p2 
)
friend

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

Definition at line 83 of file qpoint.h.

◆ operator>>()

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

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

See also
{Serializing Qt Data Types}

Definition at line 417 of file qpoint.cpp.

◆ QTransform

friend class QTransform
friend

Definition at line 115 of file qpoint.h.


The documentation for this class was generated from the following files: