?? qrect.cpp
字號:
The intersection rectangle can be retrieved using the intersected() function. \sa contains()*/bool QRect::intersects(const QRect &r) const{ if (isNull() || r.isNull()) return false; QRect r1 = normalized(); QRect r2 = r.normalized(); return (qMax(r1.x1, r2.x1) <= qMin(r1.x2, r2.x2) && qMax(r1.y1, r2.y1) <= qMin(r1.y2, r2.y2));}/*! \fn bool operator==(const QRect &r1, const QRect &r2) \relates QRect Returns true if the rectangles \a r1 and \a r2 are equal, otherwise returns false.*//*! \fn bool operator!=(const QRect &r1, const QRect &r2) \relates QRect Returns true if the rectangles \a r1 and \a r2 are different, otherwise returns false.*//***************************************************************************** QRect stream functions *****************************************************************************/#ifndef QT_NO_DATASTREAM/*! \fn QDataStream &operator<<(QDataStream &stream, const QRect &rectangle) \relates QRect Writes the given \a rectangle to the given \a stream, and returns a reference to the stream. \sa {Format of the QDataStream Operators}*/QDataStream &operator<<(QDataStream &s, const QRect &r){ if (s.version() == 1) s << (qint16)r.left() << (qint16)r.top() << (qint16)r.right() << (qint16)r.bottom(); else s << (qint32)r.left() << (qint32)r.top() << (qint32)r.right() << (qint32)r.bottom(); return s;}/*! \fn QDataStream &operator>>(QDataStream &stream, QRect &rectangle) \relates QRect Reads a rectangle from the given \a stream into the given \a rectangle, and returns a reference to the stream. \sa {Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &s, QRect &r){ if (s.version() == 1) { qint16 x1, y1, x2, y2; s >> x1; s >> y1; s >> x2; s >> y2; r.setCoords(x1, y1, x2, y2); } else { qint32 x1, y1, x2, y2; s >> x1; s >> y1; s >> x2; s >> y2; r.setCoords(x1, y1, x2, y2); } return s;}#endif // QT_NO_DATASTREAM#ifndef QT_NO_DEBUG_STREAMQDebug operator<<(QDebug dbg, const QRect &r) { dbg.nospace() << "QRect(" << r.x() << ',' << r.y() << ' ' << r.width() << 'x' << r.height() << ')'; return dbg.space();}#endif/*! \class QRectF \ingroup multimedia \brief The QRectF 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 a QRectF is always equivalent to the mathematical rectangle that forms the basis for its rendering. A QRectF can be constructed with a set of left, top, width and height integers, or from a QPoint and a QSize. The following code creates two identical rectangles. \code QRectF r1(100, 200, 11, 16); QRectF r2(QPoint(100, 200), QSize(11, 16)); \endcode There is also a third constructor creating a QRectF from a QRect, and a corresponding toRect() function that returns a QRect object based on the values of this rectangle (note that the coordinates in the returned rectangle are rounded to the nearest integer). The QRectF 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 a moveTo() function that moves the rectangle, leaving its top left corner at the given coordinates. Alternatively, the translate() function moves the rectangle the given offset relative to the current position, and the translated() function returns a translated copy of this rectangle. The size() function returns the rectange's dimensions as a QSize. The dimensions can also be retrieved separately using the width() and height() functions. To manipulate the dimensions use the setSize(), setWidth() or setHeight() functions. Alternatively, the size can be changed by applying either of the functions setting the rectangle coordinates, for example, setBottom() or setRight(). The contains() function tells whether a given point is inside the rectangle or not, and the intersects() function returns true if this rectangle intersects with a given rectangle (otherwise false). The QRectF class also provides the intersected() function which returns the intersection rectangle, and the united() function which returns the rectangle that encloses the given rectangle and this: \table \row \o \inlineimage qrect-intersect.png \o \inlineimage qrect-unite.png \row \o intersected() \o united() \endtable The isEmpty() 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: The isValid() 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. Finally, QRectF objects can be streamed as well as compared. \tableofcontents \section1 Rendering When using an \l {QPainter::Antialiasing}{anti-aliased} painter, the boundary line of a QRectF 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 the QRectF'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. \table \row \o \inlineimage qrect-diagram-zero.png \o \inlineimage qrectf-diagram-one.png \row \o Logical representation \o One pixel wide pen \row \o \inlineimage qrectf-diagram-two.png \o \inlineimage qrectf-diagram-three.png \row \o Two pixel wide pen \o Three pixel wide pen \endtable \section1 Coordinates The QRectF 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: the bottom(), setBottom() and moveBottom() 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) and moveBottom() moves the entire rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate and its size unchanged. \image qrectf-coordinates.png It is also possible to add offsets to this rectangle's coordinates using the adjust() function, as well as retrieve a new rectangle based on adjustments of the original one using the adjusted() function. If either of the width and height is negative, use the normalized() function to retrieve a rectangle where the corners are swapped. In addition, QRectF provides the getCoords() function which extracts the position of the rectangle's top-left and bottom-right corner, and the getRect() function which extracts the rectangle's top-left corner, width and height. Use the setCoords() and setRect() function to manipulate the rectangle's coordinates and dimensions in one go. \sa QRect, QRegion*//***************************************************************************** QRectF member functions *****************************************************************************//*! \fn QRectF::QRectF() Constructs a null rectangle. \sa isNull()*//*! \fn QRectF::QRectF(const QPointF &topLeft, const QSizeF &size) Constructs a rectangle with the given \a topLeft corner and the given \a size. \sa setTopLeft(), setSize()*//*! \fn QRectF::QRectF(qreal x, qreal y, qreal width, qreal height) Constructs a rectangle with (\a x, \a y) as its top-left corner and the given \a width and \a height. \sa setRect()*//*! \fn QRectF::QRectF(const QRect &rectangle) Constructs a QRectF rectangle from the given QRect \a rectangle. \sa toRect()*//*! \fn 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. \sa isEmpty(), isValid()*//*! \fn bool QRectF::isEmpty() const Returns true if the rectangle is empty, otherwise returns false. An empty rectangle has width() <= 0 or height() <= 0. An empty rectangle is not valid (i.e isEmpty() == !isValid()). Use the normalized() function to retrieve a rectangle where the corners are swapped. \sa isNull(), isValid(), normalized()*//*! \fn bool QRectF::isValid() const Returns true if the rectangle is valid, otherwise returns false. A valid rectangle has a width() > 0 and height() > 0. Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e. isValid() == !isEmpty()). \sa isNull(), isEmpty(), normalized()*//*! Returns a normalized rectangle; i.e. a rectangle that has a non-negative width and height. If width() < 0 the function swaps the left and right corners, and it swaps the top and bottom corners if height() < 0. \sa isValid(), isEmpty()*/QRectF QRectF::normalized() const{ QRectF r = *this; if (r.w < 0) { r.xp = r.xp + r.w; r.w = -r.w; } if (r.h < 0) { r.yp = r.yp + r.h; r.h = -r.h; } return r;}/*! \fn qreal QRectF::x() const Returns the x-coordinate of the rectangle's left edge. Equivalent to left(). \sa setX(), y(), topLeft()*//*! \fn qreal QRectF::y() const Returns the y-coordinate of the rectangle's top edge. Equivalent to top(). \sa setY(), x(), topLeft()*//*! \fn void QRectF::setLeft(qreal x) Sets the left edge of the rectangle to the given \a x coordinate. May change the width, but will never change the right edge of the rectangle. Equivalent to setX(). \sa left(), moveLeft()*//*! \fn void QRectF::setTop(qreal y) Sets the top edge of the rectangle to the given \a y coordinate. May change the height, but will never change the bottom edge of the rectangle. Equivalent to setY(). \sa top(), moveTop()*//*! \fn void QRectF::setRight(qreal x) Sets the right edge of the rectangle to the given \a x coordinate. May change the width, but will never change the left edge of the rectangle. \sa right(), moveRight()*//*! \fn void QRectF::setBottom(qreal y) Sets the bottom edge of the rectangle to the given \a y coordinate. May change the height, but will never change the top edge of the rectangle. \sa bottom(), moveBottom()*//*! \fn void QRectF::setX(qreal x) Sets the left edge of the rectangle to the given \a x coordinate. May change the width, but will never change the right edge of the rectangle. Equivalent to setLeft(). \sa x(), setY(), setTopLeft()*//*! \fn void QRectF::setY(qreal y) Sets the top edge of the rectangle to the given \a y coordinate. May change the height, but will never change the bottom edge of the rectangle. Equivalent to setTop(). \sa y(), setX(), setTopLeft()*//*! \fn void QRectF::setTopLeft(const QPointF &position) Set the top-left corner of the rectangle to the given \a position. May change the size, but will the never change the bottom-right corner of the rectangle. \sa topLeft(), moveTopLeft()*//*! \fn void QRectF::setBottomRight(const QPointF &position) Set the top-right corner of the rectangle to the given \a position. May change the size, but will the never change the top-left corner of the rectangle. \sa bottomRight(), moveBottomRight()*//*! \fn void QRectF::setTopRight(const QPointF &position) Set the top-right corner of the rectangle to the given \a position. May change the size, but will the never change the bottom-left corner of the rectangle. \sa topRight(), moveTopRight()*//*! \fn void QRectF::setBottomLeft(const QPointF &position) Set the bottom-left corner of the rectangle to the given \a position. May change the size, but will the never change the top-right corner of the rectangle. \sa bottomLeft(), moveBottomLeft()*//*! \fn QPointF QRectF::center() const Returns the center point of the rectangle. \sa moveCenter()*//*! \fn void QRectF::getRect(qreal *x, qreal *y, qreal *width, qreal *height) const Extracts the position of the rectangle's top-left corner to *\a x and *\a y, and its dimensions to *\a width and *\a height. \sa setRect(), getCoords()*//*! \fn void QRectF::getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const Extracts the position of the rectangle's top-left corner to *\a x1 and *\a y1, and the position of the bottom-right corner to *\a x2 and *\a y2. \sa setCoords(), getRect()*//*! \fn void QRectF::moveLeft(qreal x) Moves the rectangle horizontally, leaving the rectangle's left edge at the given \a x coordinate. The rectangle's size is unchanged. \sa left(), setLeft(), moveRight()*//*! \fn void QRectF::moveTop(qreal y) Moves the rectangle vertically, leaving the rectangle's top line at the given \a y coordinate. The rectangle's size is unchanged. \sa top(), setTop(), moveBottom()*//*! \fn void QRectF::moveRight(qreal x) Moves the rectangle horizontally, leaving the rectangle's right edge at the given \a x coordinate. The rectangle's size is unchanged. \sa right(), setRight(), moveLeft()*//*! \fn void QRectF::moveBottom(qreal y) Moves the rectangle vertically, leaving the rectangle's bottom
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -