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

QRectF Class

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

Header:#include <QRectF>

Public Functions

QRectF()
QRectF(const QPointF & topLeft, const QSizeF & size)
QRectF(const QPointF & topLeft, const QPointF & bottomRight)
QRectF(qreal x, qreal y, qreal width, qreal height)
QRectF(const QRect & rectangle)
voidadjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
QRectFadjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const
qrealbottom() const
QPointFbottomLeft() const
QPointFbottomRight() const
QPointFcenter() const
boolcontains(const QPointF & point) const
boolcontains(qreal x, qreal y) const
boolcontains(const QRectF & rectangle) const
voidgetCoords(qreal * x1, qreal * y1, qreal * x2, qreal * y2) const
voidgetRect(qreal * x, qreal * y, qreal * width, qreal * height) const
qrealheight() const
QRectFintersected(const QRectF & rectangle) const
boolintersects(const QRectF & rectangle) const
boolisEmpty() const
boolisNull() const
boolisValid() const
qrealleft() const
voidmoveBottom(qreal y)
voidmoveBottomLeft(const QPointF & position)
voidmoveBottomRight(const QPointF & position)
voidmoveCenter(const QPointF & position)
voidmoveLeft(qreal x)
voidmoveRight(qreal x)
voidmoveTo(qreal x, qreal y)
voidmoveTo(const QPointF & position)
voidmoveTop(qreal y)
voidmoveTopLeft(const QPointF & position)
voidmoveTopRight(const QPointF & position)
QRectFnormalized() const
qrealright() const
voidsetBottom(qreal y)
voidsetBottomLeft(const QPointF & position)
voidsetBottomRight(const QPointF & position)
voidsetCoords(qreal x1, qreal y1, qreal x2, qreal y2)
voidsetHeight(qreal height)
voidsetLeft(qreal x)
voidsetRect(qreal x, qreal y, qreal width, qreal height)
voidsetRight(qreal x)
voidsetSize(const QSizeF & size)
voidsetTop(qreal y)
voidsetTopLeft(const QPointF & position)
voidsetTopRight(const QPointF & position)
voidsetWidth(qreal width)
voidsetX(qreal x)
voidsetY(qreal y)
QSizeFsize() const
QRecttoAlignedRect() const
QRecttoRect() const
qrealtop() const
QPointFtopLeft() const
QPointFtopRight() const
voidtranslate(qreal dx, qreal dy)
voidtranslate(const QPointF & offset)
QRectFtranslated(qreal dx, qreal dy) const
QRectFtranslated(const QPointF & offset) const
QRectFunited(const QRectF & rectangle) const
qrealwidth() const
qrealx() const
qrealy() const
QRectFoperator&(const QRectF & rectangle) const
QRectF &operator&=(const QRectF & rectangle)
QRectFoperator|(const QRectF & rectangle) const
QRectF &operator|=(const QRectF & rectangle)

Related Non-Members

booloperator!=(const QRectF & r1, const QRectF & r2)
QDataStream &operator<<(QDataStream & stream, const QRectF & rectangle)
booloperator==(const QRectF & r1, const QRectF & r2)
QDataStream &operator>>(QDataStream & stream, QRectF & rectangle)

Detailed Description

TheQRectF class defines a rectangle in the plane using floating point precision.

A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of aQRectF is always equivalent to the mathematical rectangle that forms the basis for its rendering.

AQRectF can be constructed with a set of left, top, width and height integers, or from aQPoint and aQSize. The following code creates two identical rectangles.

QRectF r1(100,200,11,16);QRectF r2(QPoint(100,200),QSize(11,16));

There is also a third constructor creating aQRectF from aQRect, and a correspondingtoRect() function that returns aQRect object based on the values of this rectangle (note that the coordinates in the returned rectangle are rounded to the nearest integer).

TheQRectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these.QRectF also provide functions to move the rectangle relative to the various coordinates. In addition there is amoveTo() function that moves the rectangle, leaving its top left corner at the given coordinates. Alternatively, thetranslate() function moves the rectangle the given offset relative to the current position, and thetranslated() function returns a translated copy of this rectangle.

Thesize() function returns the rectange's dimensions as aQSize. The dimensions can also be retrieved separately using thewidth() andheight() functions. To manipulate the dimensions use thesetSize(),setWidth() orsetHeight() functions. Alternatively, the size can be changed by applying either of the functions setting the rectangle coordinates, for example,setBottom() orsetRight().

Thecontains() function tells whether a given point is inside the rectangle or not, and theintersects() function returns true if this rectangle intersects with a given rectangle (otherwise false). TheQRectF class also provides theintersected() function which returns the intersection rectangle, and theunited() function which returns the rectangle that encloses the given rectangle and this:

TheisEmpty() function returns true if the rectangle's width or height is less than, or equal to, 0. Note that an empty rectangle is not valid: TheisValid() function returns true if both width and height is larger than 0. A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.

Note that due to the wayQRect andQRectF are defined, an emptyQRectF is defined in essentially the same way asQRect.

Finally,QRectF objects can be streamed as well as compared.

Rendering

When using ananti-aliased painter, the boundary line of aQRectF will be rendered symmetrically on both sides of the mathematical rectangle's boundary line. But when using an aliased painter (the default) other rules apply.

Then, when rendering with a one pixel wide pen theQRectF's boundary line will be rendered to the right and below the mathematical rectangle's boundary line.

When rendering with a two pixels wide pen the boundary line will be split in the middle by the mathematical rectangle. This will be the case whenever the pen is set to an even number of pixels, while rendering with a pen with an odd number of pixels, the spare pixel will be rendered to the right and below the mathematical rectangle as in the one pixel case.

Logical representationOne pixel wide pen
Two pixel wide penThree pixel wide pen

Coordinates

TheQRectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these.QRectF also provide functions to move the rectangle relative to the various coordinates.

For example: thebottom(),setBottom() andmoveBottom() functions:bottom() returns the y-coordinate of the rectangle's bottom edge,setBottom() sets the bottom edge of the rectangle to the given y coordinate (it may change the height, but will never change the rectangle's top edge) andmoveBottom() moves the entire rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate and its size unchanged.

It is also possible to add offsets to this rectangle's coordinates using theadjust() function, as well as retrieve a new rectangle based on adjustments of the original one using theadjusted() function. If either of the width and height is negative, use thenormalized() function to retrieve a rectangle where the corners are swapped.

In addition,QRectF provides thegetCoords() function which extracts the position of the rectangle's top-left and bottom-right corner, and thegetRect() function which extracts the rectangle's top-left corner, width and height. Use thesetCoords() andsetRect() function to manipulate the rectangle's coordinates and dimensions in one go.

See alsoQRect andQRegion.

Member Function Documentation

QRectF::QRectF()

Constructs a null rectangle.

See alsoisNull().

QRectF::QRectF(constQPointF & topLeft, constQSizeF & size)

Constructs a rectangle with the giventopLeft corner and the givensize.

See alsosetTopLeft() andsetSize().

QRectF::QRectF(constQPointF & topLeft, constQPointF & bottomRight)

Constructs a rectangle with the giventopLeft andbottomRight corners.

This function was introduced in Qt 4.3.

See alsosetTopLeft() andsetBottomRight().

QRectF::QRectF(qreal x,qreal y,qreal width,qreal height)

Constructs a rectangle with (x,y) as its top-left corner and the givenwidth andheight.

See alsosetRect().

QRectF::QRectF(constQRect & rectangle)

Constructs aQRectF rectangle from the givenQRectrectangle.

See alsotoRect().

void QRectF::adjust(qreal dx1,qreal dy1,qreal dx2,qreal dy2)

Addsdx1,dy1,dx2 anddy2 respectively to the existing coordinates of the rectangle.

See alsoadjusted() andsetRect().

QRectF QRectF::adjusted(qreal dx1,qreal dy1,qreal dx2,qreal dy2) const

Returns a new rectangle withdx1,dy1,dx2 anddy2 added respectively to the existing coordinates of this rectangle.

See alsoadjust().

qreal QRectF::bottom() const

Returns the y-coordinate of the rectangle's bottom edge.

See alsosetBottom(),bottomLeft(), andbottomRight().

QPointF QRectF::bottomLeft() const

Returns the position of the rectangle's bottom-left corner.

See alsosetBottomLeft(),bottom(), andleft().

QPointF QRectF::bottomRight() const

Returns the position of the rectangle's bottom-right corner.

See alsosetBottomRight(),bottom(), andright().

QPointF QRectF::center() const

Returns the center point of the rectangle.

See alsomoveCenter().

bool QRectF::contains(constQPointF & point) const

Returns true if the givenpoint is inside or on the edge of the rectangle; otherwise returns false.

See alsointersects().

bool QRectF::contains(qreal x,qreal y) const

This is an overloaded function.

Returns true if the point (x,y) is inside or on the edge of the rectangle; otherwise returns false.

bool QRectF::contains(constQRectF & rectangle) const

This is an overloaded function.

Returns true if the givenrectangle is inside this rectangle; otherwise returns false.

void QRectF::getCoords(qreal * x1,qreal * y1,qreal * x2,qreal * y2) const

Extracts the position of the rectangle's top-left corner to *x1 and *y1, and the position of the bottom-right corner to *x2 and *y2.

See alsosetCoords() andgetRect().

void QRectF::getRect(qreal * x,qreal * y,qreal * width,qreal * height) const

Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height.

See alsosetRect() andgetCoords().

qreal QRectF::height() const

Returns the height of the rectangle.

See alsosetHeight(),width(), andsize().

QRectF QRectF::intersected(constQRectF & rectangle) const

Returns the intersection of this rectangle and the givenrectangle. Note thatr.intersected(s) is equivalent tor & s.

This function was introduced in Qt 4.2.

See alsointersects(),united(), andoperator&=().

bool QRectF::intersects(constQRectF & rectangle) const

Returns true if this rectangle intersects with the givenrectangle (i.e. there is a non-empty area of overlap between them), otherwise returns false.

The intersection rectangle can be retrieved using theintersected() function.

See alsocontains().

bool QRectF::isEmpty() const

Returns true if the rectangle is empty, otherwise returns false.

An empty rectangle haswidth() <= 0 orheight() <= 0. An empty rectangle is not valid (i.e., isEmpty() == !isValid()).

Use thenormalized() function to retrieve a rectangle where the corners are swapped.

See alsoisNull(),isValid(), andnormalized().

bool QRectF::isNull() const

Returns true if the rectangle is a null rectangle, otherwise returns false.

A null rectangle has both the width and the height set to 0. A null rectangle is also empty, and hence not valid.

See alsoisEmpty() andisValid().

bool QRectF::isValid() const

Returns true if the rectangle is valid, otherwise returns false.

A valid rectangle has awidth() > 0 andheight() > 0. Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).

See alsoisNull(),isEmpty(), andnormalized().

qreal QRectF::left() const

Returns the x-coordinate of the rectangle's left edge. Equivalent tox().

See alsosetLeft(),topLeft(), andbottomLeft().

void QRectF::moveBottom(qreal y)

Moves the rectangle vertically, leaving the rectangle's bottom edge at the giveny coordinate. The rectangle's size is unchanged.

See alsobottom(),setBottom(), andmoveTop().

void QRectF::moveBottomLeft(constQPointF & position)

Moves the rectangle, leaving the bottom-left corner at the givenposition. The rectangle's size is unchanged.

See alsosetBottomLeft(),moveBottom(), andmoveLeft().

void QRectF::moveBottomRight(constQPointF & position)

Moves the rectangle, leaving the bottom-right corner at the givenposition. The rectangle's size is unchanged.

See alsosetBottomRight(),moveBottom(), andmoveRight().

void QRectF::moveCenter(constQPointF & position)

Moves the rectangle, leaving the center point at the givenposition. The rectangle's size is unchanged.

See alsocenter().

void QRectF::moveLeft(qreal x)

Moves the rectangle horizontally, leaving the rectangle's left edge at the givenx coordinate. The rectangle's size is unchanged.

See alsoleft(),setLeft(), andmoveRight().

void QRectF::moveRight(qreal x)

Moves the rectangle horizontally, leaving the rectangle's right edge at the givenx coordinate. The rectangle's size is unchanged.

See alsoright(),setRight(), andmoveLeft().

void QRectF::moveTo(qreal x,qreal y)

Moves the rectangle, leaving the top-left corner at the given position (x,y). The rectangle's size is unchanged.

See alsotranslate() andmoveTopLeft().

void QRectF::moveTo(constQPointF & position)

This is an overloaded function.

Moves the rectangle, leaving the top-left corner at the givenposition.

void QRectF::moveTop(qreal y)

Moves the rectangle vertically, leaving the rectangle's top line at the giveny coordinate. The rectangle's size is unchanged.

See alsotop(),setTop(), andmoveBottom().

void QRectF::moveTopLeft(constQPointF & position)

Moves the rectangle, leaving the top-left corner at the givenposition. The rectangle's size is unchanged.

See alsosetTopLeft(),moveTop(), andmoveLeft().

void QRectF::moveTopRight(constQPointF & position)

Moves the rectangle, leaving the top-right corner at the givenposition. The rectangle's size is unchanged.

See alsosetTopRight(),moveTop(), andmoveRight().

QRectF QRectF::normalized() const

Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height.

Ifwidth() < 0 the function swaps the left and right corners, and it swaps the top and bottom corners ifheight() < 0.

See alsoisValid() andisEmpty().

qreal QRectF::right() const

Returns the x-coordinate of the rectangle's right edge.

See alsosetRight(),topRight(), andbottomRight().

void QRectF::setBottom(qreal y)

Sets the bottom edge of the rectangle to the giveny coordinate. May change the height, but will never change the top edge of the rectangle.

See alsobottom() andmoveBottom().

void QRectF::setBottomLeft(constQPointF & position)

Set the bottom-left corner of the rectangle to the givenposition. May change the size, but will never change the top-right corner of the rectangle.

See alsobottomLeft() andmoveBottomLeft().

void QRectF::setBottomRight(constQPointF & position)

Set the bottom-right corner of the rectangle to the givenposition. May change the size, but will never change the top-left corner of the rectangle.

See alsobottomRight() andmoveBottomRight().

void QRectF::setCoords(qreal x1,qreal y1,qreal x2,qreal y2)

Sets the coordinates of the rectangle's top-left corner to (x1,y1), and the coordinates of its bottom-right corner to (x2,y2).

See alsogetCoords() andsetRect().

void QRectF::setHeight(qreal height)

Sets the height of the rectangle to the givenheight. The bottom edge is changed, but not the top one.

See alsoheight() andsetSize().

void QRectF::setLeft(qreal x)

Sets the left edge of the rectangle to the givenx coordinate. May change the width, but will never change the right edge of the rectangle.

Equivalent tosetX().

See alsoleft() andmoveLeft().

void QRectF::setRect(qreal x,qreal y,qreal width,qreal height)

Sets the coordinates of the rectangle's top-left corner to (x,y), and its size to the givenwidth andheight.

See alsogetRect() andsetCoords().

void QRectF::setRight(qreal x)

Sets the right edge of the rectangle to the givenx coordinate. May change the width, but will never change the left edge of the rectangle.

See alsoright() andmoveRight().

void QRectF::setSize(constQSizeF & size)

Sets the size of the rectangle to the givensize. The top-left corner is not moved.

See alsosize(),setWidth(), andsetHeight().

void QRectF::setTop(qreal y)

Sets the top edge of the rectangle to the giveny coordinate. May change the height, but will never change the bottom edge of the rectangle.

Equivalent tosetY().

See alsotop() andmoveTop().

void QRectF::setTopLeft(constQPointF & position)

Set the top-left corner of the rectangle to the givenposition. May change the size, but will never change the bottom-right corner of the rectangle.

See alsotopLeft() andmoveTopLeft().

void QRectF::setTopRight(constQPointF & position)

Set the top-right corner of the rectangle to the givenposition. May change the size, but will never change the bottom-left corner of the rectangle.

See alsotopRight() andmoveTopRight().

void QRectF::setWidth(qreal width)

Sets the width of the rectangle to the givenwidth. The right edge is changed, but not the left one.

See alsowidth() andsetSize().

void QRectF::setX(qreal x)

Sets the left edge of the rectangle to the givenx coordinate. May change the width, but will never change the right edge of the rectangle.

Equivalent tosetLeft().

See alsox(),setY(), andsetTopLeft().

void QRectF::setY(qreal y)

Sets the top edge of the rectangle to the giveny coordinate. May change the height, but will never change the bottom edge of the rectangle.

Equivalent tosetTop().

See alsoy(),setX(), andsetTopLeft().

QSizeF QRectF::size() const

Returns the size of the rectangle.

See alsosetSize(),width(), andheight().

QRect QRectF::toAlignedRect() const

Returns aQRect based on the values of this rectangle that is the smallest possible integer rectangle that completely contains this rectangle.

This function was introduced in Qt 4.3.

See alsotoRect().

QRect QRectF::toRect() const

Returns aQRect based on the values of this rectangle. Note that the coordinates in the returned rectangle are rounded to the nearest integer.

See alsoQRectF() andtoAlignedRect().

qreal QRectF::top() const

Returns the y-coordinate of the rectangle's top edge. Equivalent toy().

See alsosetTop(),topLeft(), andtopRight().

QPointF QRectF::topLeft() const

Returns the position of the rectangle's top-left corner.

See alsosetTopLeft(),top(), andleft().

QPointF QRectF::topRight() const

Returns the position of the rectangle's top-right corner.

See alsosetTopRight(),top(), andright().

void QRectF::translate(qreal dx,qreal dy)

Moves the rectangledx along the x-axis anddy along the y-axis, relative to the current position. Positive values move the rectangle to the right and downwards.

See alsomoveTopLeft(),moveTo(), andtranslated().

void QRectF::translate(constQPointF & offset)

This is an overloaded function.

Moves the rectangleoffset.x() along the x axis andoffset.y() along the y axis, relative to the current position.

QRectF QRectF::translated(qreal dx,qreal dy) const

Returns a copy of the rectangle that is translateddx along the x axis anddy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.

See alsotranslate().

QRectF QRectF::translated(constQPointF & offset) const

This is an overloaded function.

Returns a copy of the rectangle that is translatedoffset.x() along the x axis andoffset.y() along the y axis, relative to the current position.

QRectF QRectF::united(constQRectF & rectangle) const

Returns the bounding rectangle of this rectangle and the givenrectangle.

This function was introduced in Qt 4.2.

See alsointersected().

qreal QRectF::width() const

Returns the width of the rectangle.

See alsosetWidth(),height(), andsize().

qreal QRectF::x() const

Returns the x-coordinate of the rectangle's left edge. Equivalent toleft().

See alsosetX(),y(), andtopLeft().

qreal QRectF::y() const

Returns the y-coordinate of the rectangle's top edge. Equivalent totop().

See alsosetY(),x(), andtopLeft().

QRectF QRectF::operator&(constQRectF & rectangle) const

Returns the intersection of this rectangle and the givenrectangle. Returns an empty rectangle if there is no intersection.

See alsooperator&=() andintersected().

QRectF & QRectF::operator&=(constQRectF & rectangle)

Intersects this rectangle with the givenrectangle.

See alsointersected() andoperator|=().

QRectF QRectF::operator|(constQRectF & rectangle) const

Returns the bounding rectangle of this rectangle and the givenrectangle.

See alsounited() andoperator|=().

QRectF & QRectF::operator|=(constQRectF & rectangle)

Unites this rectangle with the givenrectangle.

See alsounited() andoperator|().

Related Non-Members

booloperator!=(constQRectF & r1, constQRectF & r2)

Returns true if the rectanglesr1 andr2 are different, otherwise returns false.

QDataStream &operator<<(QDataStream & stream, constQRectF & rectangle)

Writes therectangle to thestream, and returns a reference to the stream.

See alsoSerializing Qt Data Types.

booloperator==(constQRectF & r1, constQRectF & r2)

Returns true if the rectanglesr1 andr2 are equal, otherwise returns false.

QDataStream &operator>>(QDataStream & stream,QRectF & rectangle)

Reads arectangle from thestream, 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