6.0.0-rc4Source

QPoint Class

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

Header#include <QPoint>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QPoint()
QPoint(int xpos, int ypos)
boolisNull() const
intx() const
inty() const
voidsetX(int x)
voidsetY(int y)
int &rx()
int &ry()
intmanhattanLength() const
QPointtransposed() const
QPointFtoPointF() const
QPoint &operator+=(const QPoint &p)
QPoint &operator-=(const QPoint &p)
QPoint &operator*=(int f)
QPoint &operator*=(double f)
QPoint &operator/=(double d)

Static Public Members

intdotProduct(const QPoint &a, const QPoint &b)

Detailed Description

A point is specified by an x coordinate and a y coordinate, both stored as int. The default point is the origin (0, 0). Use QPointF for floating-point coordinates.

Points can be added, subtracted and scaled with the usual operators. Multiplying or dividing by a double rounds each coordinate to the nearest integer.

See also QPointF and QLine.

Differences from Qt

There are no operator*() or operator/() overloads taking float or qreal other than double, and no platform conversions such as toCGPoint().

Member Function Documentation

[constexpr] QPoint::QPoint()

Constructs a null point, that is, a point with coordinates (0, 0).

See also isNull().

[constexpr] QPoint::QPoint(int xpos, int ypos)

Constructs a point with coordinates (xpos, ypos).

[static, constexpr] int QPoint::dotProduct(const QPoint &a, const QPoint &b)

Returns the dot product of a and b.

[constexpr] bool QPoint::isNull() const

Returns true if both the x and y coordinates are 0; otherwise returns false.

[constexpr] int QPoint::manhattanLength() const

Returns the sum of the absolute values of x() and y(), the distance of the point from the origin measured along the axes.

[constexpr] QPoint & QPoint::operator*=(int f)

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

QPoint & QPoint::operator*=(double f)

This is an overloaded function.

Multiplies this point's coordinates by the given f and rounds each result to the nearest integer.

[constexpr] QPoint & QPoint::operator+=(const QPoint &p)

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

[constexpr] QPoint & QPoint::operator-=(const QPoint &p)

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

QPoint & QPoint::operator/=(double d)

Divides both coordinates of this point by the given divisor d, rounds each result to the nearest integer, and returns a reference to this point.

[constexpr] int & QPoint::rx()

Returns a reference to the x coordinate of this point, allowing it to be modified directly.

See also x() and setX().

[constexpr] int & QPoint::ry()

Returns a reference to the y coordinate of this point, allowing it to be modified directly.

See also y() and setY().

[constexpr] void QPoint::setX(int x)

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

See also x() and setY().

[constexpr] void QPoint::setY(int y)

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

See also y() and setX().

[constexpr] QPointF QPoint::toPointF() const

Returns this point as a QPointF.

See also QPointF::toPoint().

[constexpr] QPoint QPoint::transposed() const

Returns a point with the x and y coordinates exchanged.

See also QPointF::transposed().

[constexpr] int QPoint::x() const

Returns the x coordinate of this point.

See also setX() and rx().

[constexpr] int QPoint::y() const

Returns the y coordinate of this point.

See also setY() and ry().