QPoint Class
The QPoint class defines a point in the plane using integer precision. More…
| Header | #include <QPoint> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QPoint() | |
| QPoint(int xpos, int ypos) | |
| bool | isNull() const |
| int | x() const |
| int | y() const |
| void | setX(int x) |
| void | setY(int y) |
| int & | rx() |
| int & | ry() |
| int | manhattanLength() const |
| QPoint | transposed() const |
| QPointF | toPointF() 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
| int | dotProduct(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.
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
QPoint::QPoint()
Constructs a null point, that is, a point with coordinates (0, 0).
See also isNull().
QPoint::QPoint(int xpos, int ypos)
Constructs a point with coordinates (xpos, ypos).
int QPoint::dotProduct(const QPoint &a, const QPoint &b)
Returns the dot product of a and b.
bool QPoint::isNull() const
Returns true if both the x and y coordinates are 0; otherwise returns false.
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.
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.
QPoint & QPoint::operator+=(const QPoint &p)
Adds the given p to this point and returns a reference to this point.
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.
int & QPoint::rx()
Returns a reference to the x coordinate of this point, allowing it to be modified directly.
int & QPoint::ry()
Returns a reference to the y coordinate of this point, allowing it to be modified directly.
void QPoint::setX(int x)
Sets the x coordinate of this point to the given x coordinate.
void QPoint::setY(int y)
Sets the y coordinate of this point to the given y coordinate.
QPointF QPoint::toPointF() const
Returns this point as a QPointF.
See also QPointF::toPoint().
QPoint QPoint::transposed() const
Returns a point with the x and y coordinates exchanged.
See also QPointF::transposed().
int QPoint::x() const
Returns the x coordinate of this point.
int QPoint::y() const
Returns the y coordinate of this point.