Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QPointF Class Reference

\inmodule QtCore\reentrant More...

#include <qpoint.h>

+ Inheritance diagram for QPointF:
+ Collaboration diagram for QPointF:

Public Member Functions

constexpr QPointF () noexcept
 Constructs a null point, i.e.
 
constexpr QPointF (const QPoint &p) noexcept
 Constructs a copy of the given point.
 
constexpr QPointF (qreal xpos, qreal ypos) noexcept
 Constructs a point with the given coordinates (xpos, ypos).
 
constexpr qreal manhattanLength () const
 
bool isNull () const noexcept
 Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns false.
 
constexpr qreal x () const noexcept
 Returns the x coordinate of this point.
 
constexpr qreal y () const noexcept
 Returns the y coordinate of this point.
 
constexpr void setX (qreal x) noexcept
 Sets the x coordinate of this point to the given finite x coordinate.
 
constexpr void setY (qreal y) noexcept
 Sets the y coordinate of this point to the given finite y coordinate.
 
constexpr QPointF transposed () const noexcept
 
constexpr qrealrx () noexcept
 Returns a reference to the x coordinate of this point.
 
constexpr qrealry () noexcept
 Returns a reference to the y coordinate of this point.
 
constexpr QPointFoperator+= (const QPointF &p)
 Adds the given point to this point and returns a reference to this point.
 
constexpr QPointFoperator-= (const QPointF &p)
 Subtracts the given point from this point and returns a reference to this point.
 
constexpr QPointFoperator*= (qreal c)
 Multiplies this point's coordinates by the given finite factor, and returns a reference to this point.
 
constexpr QPointFoperator/= (qreal c)
 Divides both x and y by the given divisor, and returns a reference to this point.
 
constexpr QPoint toPoint () const
 Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rounded coordinates.
 

Static Public Member Functions

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

Friends

class QTransform
 
QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE friend constexpr bool qFuzzyCompare (const QPointF &p1, const QPointF &p2) noexcept
 
QT_WARNING_POP friend constexpr bool qFuzzyIsNull (const QPointF &point) noexcept
 
constexpr bool comparesEqual (const QPointF &p1, const QPointF &p2) noexcept
 
constexpr bool comparesEqual (const QPointF &p1, const QPoint &p2) noexcept
 
constexpr QPointF operator+ (const QPointF &p1, const QPointF &p2)
 Returns a QPointF object that is the sum of the given points, p1 and p2; each component is added separately.
 
constexpr QPointF operator- (const QPointF &p1, const QPointF &p2)
 Returns a QPointF object that is formed by subtracting p2 from p1; each component is subtracted separately.
 
constexpr QPointF operator* (const QPointF &p, qreal c)
 Returns a copy of the given point, multiplied by the given finite factor.
 
constexpr QPointF operator* (qreal c, const QPointF &p)
 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.
 
constexpr QPointF operator+ (const QPointF &p)
 
constexpr QPointF operator- (const QPointF &p)
 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.
 
constexpr QPointF operator/ (const QPointF &p, qreal divisor)
 Returns the QPointF object formed by dividing each component of the given point by the given divisor.
 
template<std::size_t I, typename P , std::enable_if_t<(I< 2), bool > = true, std::enable_if_t< std::is_same_v< q20::remove_cvref_t< P >, QPointF >, bool > = true>
constexpr decltype(auto) get (P &&p) noexcept
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &stream, const QPointF &point)
 Writes the given point to the given stream and returns a reference to the stream.
 
QDataStreamoperator>> (QDataStream &stream, QPointF &point)
 Reads a point from the given stream into the given point and returns a reference to the stream.
 

Detailed Description

\inmodule QtCore

\reentrant

\compares equality \compareswith equality QPoint \endcompareswith

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

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:

p.setX(p.x() + 1.0);
p += QPointF(1.0, 0.0);
p.rx()++;

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 216 of file qpoint.h.

Constructor & Destructor Documentation

◆ QPointF() [1/3]

QPointF::QPointF ( )
inlineconstexprnoexcept

Constructs a null point, i.e.

with coordinates (0.0, 0.0)

See also
isNull()

Definition at line 327 of file qpoint.h.

Referenced by QPinchGestureRecognizer::reset(), QTapAndHoldGestureRecognizer::reset(), and QTapGestureRecognizer::reset().

+ Here is the caller graph for this function:

◆ QPointF() [2/3]

QPointF::QPointF ( const QPoint & point)
inlineconstexprnoexcept

Constructs a copy of the given point.

See also
toPoint(), QPoint::toPointF()

Definition at line 331 of file qpoint.h.

◆ QPointF() [3/3]

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

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

See also
setX(), setY()

Definition at line 329 of file qpoint.h.

Member Function Documentation

◆ dotProduct()

static constexpr qreal QPointF::dotProduct ( const QPointF & p1,
const QPointF & p2 )
inlinestaticconstexpr
Since
5.1
QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
qreal dotProduct = QPointF::dotProduct(p, q); // dotProduct becomes 26.01
static constexpr qreal dotProduct(const QPointF &p1, const QPointF &p2)
Definition qpoint.h:242
constexpr int manhattanLength() const
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" ...
Definition qpoint.h:150
static constexpr int dotProduct(const QPoint &p1, const QPoint &p2)
Definition qpoint.h:53
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:140
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition qwidget.cpp:9507
QPoint oldPosition
[6]
double trueLength
[7]

Returns the dot product of p1 and p2.

Definition at line 242 of file qpoint.h.

◆ 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 338 of file qpoint.h.

◆ manhattanLength()

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 333 of file qpoint.h.

◆ operator*=()

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:

QPointF p(-1.1, 4.1);
p *= 2.5; // p becomes (-2.75, 10.25)
See also
operator/=()

Definition at line 387 of file qpoint.h.

◆ operator+=()

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

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

For example:

QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
p += q; // p becomes (2.1, 11.2)
See also
operator-=()

Definition at line 373 of file qpoint.h.

◆ operator-=()

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

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

For example:

QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
p -= q; // p becomes (4.1, 3.0)
See also
operator+=()

Definition at line 380 of file qpoint.h.

◆ operator/=()

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

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

For example:

QPointF p(-2.75, 10.25);
p /= 2.5; // p becomes (-1.1, 4.1)

The divisor must not be zero or NaN.

See also
operator*=()

Definition at line 394 of file qpoint.h.

◆ rx()

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:

QPointF p(1.1, 2.5);
p.rx()--; // p becomes (0.1, 2.5)
See also
x(), setX()

Definition at line 363 of file qpoint.h.

◆ ry()

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:

QPointF p(1.1, 2.5);
p.ry()++; // p becomes (1.1, 3.5)
See also
y(), setY()

Definition at line 368 of file qpoint.h.

◆ setX()

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 353 of file qpoint.h.

◆ setY()

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 358 of file qpoint.h.

◆ toPoint()

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(), QPoint::toPointF()

Definition at line 404 of file qpoint.h.

◆ transposed()

QPointF 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}
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr QPointF transposed() const noexcept
Definition qpoint.h:232
See also
x(), y(), setX(), setY()

Definition at line 232 of file qpoint.h.

◆ x()

qreal QPointF::x ( ) const
inlineconstexprnoexcept

Returns the x coordinate of this point.

See also
setX(), rx()

Definition at line 343 of file qpoint.h.

◆ y()

qreal QPointF::y ( ) const
inlineconstexprnoexcept

Returns the y coordinate of this point.

See also
setY(), ry()

Definition at line 348 of file qpoint.h.

Friends And Related Symbol Documentation

◆ comparesEqual [1/2]

bool comparesEqual ( const QPointF & p1,
const QPoint & p2 )
friend

Definition at line 263 of file qpoint.h.

◆ comparesEqual [2/2]

bool comparesEqual ( const QPointF & p1,
const QPointF & p2 )
friend

Definition at line 260 of file qpoint.h.

◆ get

template<std::size_t I, typename P , std::enable_if_t<(I< 2), bool > = true, std::enable_if_t< std::is_same_v< q20::remove_cvref_t< P >, QPointF >, bool > = true>
decltype(auto) get ( P && p)
friend

Definition at line 302 of file qpoint.h.

◆ operator* [1/2]

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 270 of file qpoint.h.

◆ operator* [2/2]

QPointF operator* ( qreal c,
const QPointF & p )
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 272 of file qpoint.h.

◆ operator+ [1/2]

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

Returns point unmodified.

Definition at line 274 of file qpoint.h.

◆ operator+ [2/2]

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 266 of file qpoint.h.

◆ operator- [1/2]

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 276 of file qpoint.h.

◆ operator- [2/2]

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 268 of file qpoint.h.

◆ operator/

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 278 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}

◆ 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}

◆ qFuzzyCompare

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE friend constexpr bool qFuzzyCompare ( const QPointF & p1,
const QPointF & p2 )
friend
Since
6.8

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

See also
qFuzzyIsNull

Definition at line 250 of file qpoint.h.

◆ qFuzzyIsNull

QT_WARNING_POP friend constexpr bool qFuzzyIsNull ( const QPointF & point)
friend
Since
6.8

Returns true if point is approximately equal to a point {(0.0, 0.0)}.

See also
qFuzzyCompare

Definition at line 256 of file qpoint.h.

◆ QTransform

friend class QTransform
friend

Definition at line 293 of file qpoint.h.


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