Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QPointF Class

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

Header:#include <QPointF>

Public Functions

QPointF()
QPointF(const QPoint & point)
QPointF(qreal x, qreal y)
boolisNull() const
qrealmanhattanLength() const
qreal &rx()
qreal &ry()
voidsetX(qreal x)
voidsetY(qreal y)
QPointtoPoint() const
qrealx() const
qrealy() const
QPointF &operator*=(qreal factor)
QPointF &operator+=(const QPointF & point)
QPointF &operator-=(const QPointF & point)
QPointF &operator/=(qreal divisor)

Related Non-Members

booloperator!=(const QPointF & p1, const QPointF & p2)
const QPointFoperator*(qreal factor, const QPointF & point)
const QPointFoperator*(const QPointF & point, qreal factor)
const QPointFoperator+(const QPointF & p1, const QPointF & p2)
const QPointFoperator-(const QPointF & p1, const QPointF & p2)
const QPointFoperator-(const QPointF & point)
const QPointFoperator/(const QPointF & point, qreal divisor)
QDataStream &operator<<(QDataStream & stream, const QPointF & point)
booloperator==(const QPointF & p1, const QPointF & p2)
QDataStream &operator>>(QDataStream & stream, QPointF & point)

Detailed Description

TheQPointF 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 thex() andy() functions. The coordinates of the point are specified using floating point numbers for accuracy. TheisNull() function returns true if both x and y are set to 0.0. The coordinates can be set (or altered) using thesetX() andsetY() functions, or alternatively therx() andry() functions which return references to the coordinates (allowing direct manipulation).

Given a pointp, the following statements are all equivalent:

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

AQPointF object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). AQPointF object can also be divided or multiplied by anint or aqreal.

In addition, theQPointF class provides a constructor converting aQPoint object into aQPointF object, and a correspondingtoPoint() function which returns aQPoint copy ofthis point. Finally,QPointF objects can be streamed as well as compared.

See alsoQPoint andQPolygonF.

Member Function Documentation

QPointF::QPointF()

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

See alsoisNull().

QPointF::QPointF(constQPoint & point)

Constructs a copy of the givenpoint.

See alsotoPoint().

QPointF::QPointF(qreal x,qreal y)

Constructs a point with the given coordinates (x,y).

See alsosetX() andsetY().

bool QPointF::isNull() const

Returns true if both the x and y coordinates are set to +0.0; otherwise returns false.

Note:Since this function treats +0.0 and -0.0 differently, points with zero-valued coordinates where either or both values have a negative sign are not defined to be null points.

qreal QPointF::manhattanLength() const

Returns the sum of the absolute values ofx() andy(), traditionally known as the "Manhattan length" of the vector from the origin to the point.

This function was introduced in Qt 4.6.

See alsoQPoint::manhattanLength().

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:

QPointF p(1.1,2.5); p.rx()--;// p becomes (0.1, 2.5)

See alsox() andsetX().

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:

QPointF p(1.1,2.5);p.ry()++;// p becomes (1.1, 3.5)

See alsoy() andsetY().

void QPointF::setX(qreal x)

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

See alsox() andsetY().

void QPointF::setY(qreal y)

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

See alsoy() andsetX().

QPoint QPointF::toPoint() const

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

See alsoQPointF().

qreal QPointF::x() const

Returns the x-coordinate of this point.

See alsosetX() andrx().

qreal QPointF::y() const

Returns the y-coordinate of this point.

See alsosetY() andry().

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

Multiplies this point's coordinates by the givenfactor, 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 alsooperator/=().

QPointF & QPointF::operator+=(constQPointF & point)

Adds the givenpoint 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 alsooperator-=().

QPointF & QPointF::operator-=(constQPointF & point)

Subtracts the givenpoint 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 alsooperator+=().

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

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

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

See alsooperator*=().

Related Non-Members

booloperator!=(constQPointF & p1, constQPointF & p2)

Returns true ifp1 is not equal top2; otherwise returns false.

constQPointFoperator*(qreal factor, constQPointF & point)

This is an overloaded function.

Returns a copy of the givenpoint, multiplied by the givenfactor.

constQPointFoperator*(constQPointF & point,qreal factor)

Returns a copy of the givenpoint, multiplied by the givenfactor.

See alsoQPointF::operator*=().

constQPointFoperator+(constQPointF & p1, constQPointF & p2)

Returns aQPointF object that is the sum of the given points,p1 andp2; each component is added separately.

See alsoQPointF::operator+=().

constQPointFoperator-(constQPointF & p1, constQPointF & p2)

Returns aQPointF object that is formed by subtractingp2 fromp1; each component is subtracted separately.

See alsoQPointF::operator-=().

constQPointFoperator-(constQPointF & point)

This is an overloaded function.

Returns aQPointF object that is formed by changing the sign of both components of the givenpoint.

Equivalent toQPointF(0,0) - point.

constQPointFoperator/(constQPointF & point,qreal divisor)

Returns theQPointF object formed by dividing both components of the givenpoint by the givendivisor.

See alsoQPointF::operator/=().

QDataStream &operator<<(QDataStream & stream, constQPointF & point)

Writes the givenpoint to the givenstream and returns a reference to the stream.

See alsoSerializing Qt Data Types.

booloperator==(constQPointF & p1, constQPointF & p2)

Returns true ifp1 is equal top2; otherwise returns false.

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

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

See alsoSerializing Qt Data Types.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp