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

The QPointF class defines a point in the plane using floating point precision. More...

#include <qpoint.h>

Public Member Functions

constexpr QPointF () noexcept
 
constexpr QPointF (const QPoint &p) noexcept
 
constexpr QPointF (qreal xpos, qreal ypos) noexcept
 
constexpr qreal manhattanLength () const
 
bool isNull () const noexcept
 
constexpr qreal x () const noexcept
 
constexpr qreal y () const noexcept
 
constexpr void setX (qreal x) noexcept
 
constexpr void setY (qreal y) noexcept
 
constexpr QPointF transposed () const noexcept
 
constexpr qrealrx () noexcept
 
constexpr qrealry () noexcept
 
constexpr QPointFoperator+= (const QPointF &p)
 
constexpr QPointFoperator-= (const QPointF &p)
 
constexpr QPointFoperator*= (qreal c)
 
constexpr QPointFoperator/= (qreal c)
 
constexpr QPoint toPoint () const
 

Static Public Member Functions

constexpr static qreal dotProduct (const QPointF &p1, const QPointF &p2)
 

Friends

class QTransform
 
QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr friend bool operator== (const QPointF &p1, const QPointF &p2)
 
constexpr friend bool operator!= (const QPointF &p1, const QPointF &p2)
 
QT_WARNING_POP constexpr friend QPointF operator+ (const QPointF &p1, const QPointF &p2)
 
constexpr friend QPointF operator- (const QPointF &p1, const QPointF &p2)
 
constexpr friend QPointF operator* (const QPointF &p, qreal c)
 
constexpr friend QPointF operator* (qreal c, const QPointF &p)
 
constexpr friend QPointF operator+ (const QPointF &p)
 
constexpr friend QPointF operator- (const QPointF &p)
 
constexpr friend QPointF operator/ (const QPointF &p, qreal divisor)
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

The QPointF class defines a point in the plane using floating point 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 coordinates of the point are specified using finite floating point numbers for accuracy. The isNull() function returns true if both x and y are set to 0.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 QPointF object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). A QPointF object can also be divided or multiplied by an int or a qreal.

In addition, the QPointF class provides a constructor converting a QPoint object into a QPointF object, and a corresponding toPoint() function which returns a QPoint copy of this point. Finally, QPointF objects can be streamed as well as compared.

See also
QPoint, QPolygonF

Definition at line 241 of file qpoint.h.

Constructor & Destructor Documentation

◆ QPointF() [1/3]

constexpr QPointF::QPointF ( )
inlineconstexprnoexcept

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

See also
isNull()

Definition at line 345 of file qpoint.h.

◆ QPointF() [2/3]

constexpr QPointF::QPointF ( const QPoint point)
inlineconstexprnoexcept

Constructs a copy of the given point.

See also
toPoint()

Definition at line 349 of file qpoint.h.

◆ QPointF() [3/3]

constexpr QPointF::QPointF ( qreal  xpos,
qreal  ypos 
)
inlineconstexprnoexcept

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

See also
setX(), setY()

Definition at line 347 of file qpoint.h.

Member Function Documentation

◆ dotProduct()

static qreal QPointF::dotProduct ( const QPointF p1,
const QPointF p2 
)
inlinestaticconstexpr
Since
5.1

Returns the dot product of p1 and p2.

Definition at line 267 of file qpoint.h.

Here is the caller graph for this function:

◆ isNull()

bool QPointF::isNull ( ) const
inlinenoexcept

Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns false.

Definition at line 356 of file qpoint.h.

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

◆ manhattanLength()

constexpr qreal QPointF::manhattanLength ( ) const
inlineconstexpr
Since
4.6

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.

See also
QPoint::manhattanLength()

Definition at line 351 of file qpoint.h.

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

◆ operator*=()

constexpr QPointF & QPointF::operator*= ( qreal  factor)
inlineconstexpr

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

See also
operator/=()

Definition at line 405 of file qpoint.h.

◆ operator+=()

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

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

See also
operator-=()

Definition at line 391 of file qpoint.h.

◆ operator-=()

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

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

See also
operator+=()

Definition at line 398 of file qpoint.h.

◆ operator/=()

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

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

The divisor must not be zero or NaN.

See also
operator*=()

Definition at line 412 of file qpoint.h.

◆ rx()

constexpr qreal & QPointF::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 381 of file qpoint.h.

Here is the caller graph for this function:

◆ ry()

constexpr qreal & QPointF::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 386 of file qpoint.h.

Here is the caller graph for this function:

◆ setX()

constexpr void QPointF::setX ( qreal  x)
inlineconstexprnoexcept

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

See also
x(), setY()

Definition at line 371 of file qpoint.h.

Here is the caller graph for this function:

◆ setY()

constexpr void QPointF::setY ( qreal  y)
inlineconstexprnoexcept

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

See also
y(), setX()

Definition at line 376 of file qpoint.h.

Here is the caller graph for this function:

◆ toPoint()

constexpr QPoint QPointF::toPoint ( ) const
inlineconstexpr

Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rounded coordinates.

See also
QPointF()

Definition at line 420 of file qpoint.h.

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

◆ transposed()

QPointF::transposed ( ) const
inlineconstexprnoexcept
Since
5.14

Returns a point with x and y coordinates exchanged:

QPointF{1.0, 2.0}.transposed() // {2.0, 1.0}
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
constexpr QPointF transposed() const noexcept
Definition: qpoint.h:257
See also
x(), y(), setX(), setY()

Definition at line 257 of file qpoint.h.

◆ x()

constexpr qreal QPointF::x ( ) const
inlineconstexprnoexcept

Returns the x coordinate of this point.

See also
setX(), rx()

Definition at line 361 of file qpoint.h.

Here is the caller graph for this function:

◆ y()

constexpr qreal QPointF::y ( ) const
inlineconstexprnoexcept

Returns the y coordinate of this point.

See also
setY(), ry()

Definition at line 366 of file qpoint.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

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

Returns true if p1 is sufficiently different from p2; otherwise returns false.

Warning
This function does not check for strict inequality; instead, it uses a fuzzy comparison to compare the points' coordinates.
See also
qFuzzyCompare

Definition at line 279 of file qpoint.h.

◆ operator* [1/2]

QPointF QPointF::operator* ( const QPointF point,
qreal  factor 
)
friend

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

See also
QPointF::operator*=()

Definition at line 289 of file qpoint.h.

◆ operator* [2/2]

QPointF QPointF::operator* ( qreal  factor,
const QPointF 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 finite factor.

Definition at line 291 of file qpoint.h.

◆ operator+ [1/2]

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

Returns point unmodified.

Definition at line 293 of file qpoint.h.

◆ operator+ [2/2]

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

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

See also
QPointF::operator+=()

Definition at line 285 of file qpoint.h.

◆ operator- [1/2]

QPointF QPointF::operator- ( const QPointF 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 QPointF object that is formed by changing the sign of each component of the given point.

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

Definition at line 295 of file qpoint.h.

◆ operator- [2/2]

QPointF QPointF::operator- ( const QPointF p1,
const QPointF p2 
)
friend

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

See also
QPointF::operator-=()

Definition at line 287 of file qpoint.h.

◆ operator/

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

Returns the QPointF object formed by dividing each component of the given point by the given divisor.

The divisor must not be zero or NaN.

See also
QPointF::operator/=()

Definition at line 297 of file qpoint.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QPointF 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 794 of file qpoint.cpp.

◆ operator==

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

Returns true if p1 is approximately equal to p2; otherwise returns false.

Warning
This function does not check for strict equality; instead, it uses a fuzzy comparison to compare the points' coordinates.
See also
qFuzzyCompare

Definition at line 274 of file qpoint.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QPointF 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 810 of file qpoint.cpp.

◆ QTransform

friend class QTransform
friend

Definition at line 311 of file qpoint.h.


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