IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QPointF Class

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

All functions in this class are reentrant.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QPointF Class

  • Header: QPointF

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Inherited By:

  • Group: QPointF is part of painting

Detailed Description

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:

 
Sélectionnez
QPointF p;

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

See also QPoint, QPolygonF

Member Function Documentation

 

[constexpr] QPointF::QPointF()

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

See Also

See also isNull()

[constexpr] QPointF::QPointF(const QPoint &point)

Constructs a copy of the given point.

See Also

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

[constexpr] QPointF::QPointF(qreal xpos, qreal ypos)

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

See Also

See also setX(), setY()

[static constexpr, since 5.1] qreal QPointF::dotProduct(const QPointF &p1, const QPointF &p2)

 
Sélectionnez
QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
qreal dotProduct = QPointF::dotProduct(p, q);   // dotProduct becomes 26.01

Returns the dot product of p1 and p2.

This function was introduced in Qt 5.1.

[static, since 5.8] QPointF QPointF::fromCGPoint(CGPoint point)

Creates a QRectF from CGPoint point.

This function was introduced in Qt 5.8.

See Also

See also toCGPoint()

bool QPointF::isNull() const

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

[constexpr] qreal QPointF::manhattanLength() const

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

[constexpr] qreal &QPointF::rx()

Returns a reference to the x coordinate of this point.

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

 
Sélectionnez
 QPointF p(1.1, 2.5);
 p.rx()--;   // p becomes (0.1, 2.5)
See Also

See also x(), setX()

[constexpr] qreal &QPointF::ry()

Returns a reference to the y coordinate of this point.

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

 
Sélectionnez
QPointF p(1.1, 2.5);
p.ry()++;   // p becomes (1.1, 3.5)
See Also

See also y(), setY()

[constexpr] void QPointF::setX(qreal x)

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

See Also

See also x(), setY()

[constexpr] void QPointF::setY(qreal y)

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

See Also

See also y(), setX()

[since 5.8] CGPoint QPointF::toCGPoint() const

Creates a CGPoint from a QPointF.

This function was introduced in Qt 5.8.

See Also

See also fromCGPoint()

[constexpr] QPoint QPointF::toPoint() const

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

See Also

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

[constexpr, since 5.14] QPointF QPointF::transposed() const

Returns a point with x and y coordinates exchanged:

 
Sélectionnez
QPointF{1.0, 2.0}.transposed() // {2.0, 1.0}

This function was introduced in Qt 5.14.

See Also

See also x(), y(), setX(), setY()

[constexpr] qreal QPointF::x() const

Returns the x coordinate of this point.

See Also

See also setX(), rx()

[constexpr] qreal QPointF::y() const

Returns the y coordinate of this point.

See Also

See also setY(), ry()

[constexpr] QPointF &QPointF::operator*=(qreal factor)

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

 
Sélectionnez
QPointF p(-1.1, 4.1);
p *= 2.5;    // p becomes (-2.75, 10.25)
See Also

See also operator/=()

[constexpr] QPointF &QPointF::operator+=(const QPointF &point)

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

 
Sélectionnez
QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
p += q;    // p becomes (2.1, 11.2)
See Also

See also operator-=()

[constexpr] QPointF &QPointF::operator-=(const QPointF &point)

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

 
Sélectionnez
QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
p -= q;    // p becomes (4.1, 3.0)
See Also

See also operator+=()

[constexpr] QPointF &QPointF::operator/=(qreal divisor)

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

 
Sélectionnez
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

See also operator*=()

Related Non-Members

 

[constexpr] bool operator!=(const QPointF &p1, const QPointF &p2)

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

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

See Also

See also qFuzzyCompare

[constexpr] QPointF operator*(const QPointF &point, qreal factor)

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

See Also

See also QPointF::operator*=()

[constexpr] QPointF operator*(qreal factor, const QPointF &point)

This is an overloaded function.

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

[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.

See Also

See also QPointF::operator+=()

[constexpr, since 5.0] QPointF operator+(const QPointF &point)

Returns point unmodified.

This function was introduced in Qt 5.0.

[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.

See Also

See also QPointF::operator-=()

[constexpr] QPointF operator-(const QPointF &point)

This is an overloaded function.

Returns a QPointF object that is formed by changing the sign of each component of the given point.

Equivalent to QPointF(0,0) - point.

[constexpr] QPointF operator/(const QPointF &point, qreal divisor)

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

See also QPointF::operator/=()

QDataStream &operator<<(QDataStream &stream, const QPointF &point)

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

See Also

[constexpr] bool operator==(const QPointF &p1, const QPointF &p2)

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

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

See Also

See also qFuzzyCompare

QDataStream &operator>>(QDataStream &stream, QPointF &point)

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

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+