📄 qrect.cpp
字号:
QPoint(left() + width() -1, top() + height() - 1). \sa setBottomRight(), bottom(), right()*//*! \fn QPoint QRect::topRight() const Returns the position of the rectangle's top-right corner. Note that for historical reasons this function returns QPoint(left() + width() -1, top()). \sa setTopRight(), top(), right()*//*! \fn QPoint QRect::bottomLeft() const Returns the position of the rectangle's bottom-left corner. Note that for historical reasons this function returns QPoint(left(), top() + height() - 1). \sa setBottomLeft(), bottom(), left()*//*! \fn QPoint QRect::center() const Returns the center point of the rectangle. \sa moveCenter()*//*! \fn void QRect::getRect(int *x, int *y, int *width, int *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 QRect::getCoords(int *x1, int *y1, int *x2, int *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 QRect::rect(int *x, int *y, int *width, int *height) const \compat 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. Use the getRect() function instead.*//*! \fn void QRect::coords(int *x1, int *y1, int *x2, int *y2) const \compat 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. Use the getCoords() function instead.*//*! \fn void QRect::moveLeft(int 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 QRect::moveTop(int y) Moves the rectangle vertically, leaving the rectangle's top edge at the given \a y coordinate. The rectangle's size is unchanged. \sa top(), setTop(), moveBottom()*//*! \fn void QRect::moveRight(int 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 QRect::moveBottom(int y) Moves the rectangle vertically, leaving the rectangle's bottom edge at the given \a y coordinate. The rectangle's size is unchanged. \sa bottom(), setBottom(), moveTop()*//*! \fn void QRect::moveTopLeft(const QPoint &position) Moves the rectangle, leaving the top-left corner at the given \a position. The rectangle's size is unchanged. \sa setTopLeft(), moveTop(), moveLeft()*//*! \fn void QRect::moveBottomRight(const QPoint &position) Moves the rectangle, leaving the bottom-right corner at the given \a position. The rectangle's size is unchanged. \sa setBottomRight(), moveRight(), moveBottom()*//*! \fn void QRect::moveTopRight(const QPoint &position) Moves the rectangle, leaving the top-right corner at the given \a position. The rectangle's size is unchanged. \sa setTopRight(), moveTop(), moveRight()*//*! \fn void QRect::moveBottomLeft(const QPoint &position) Moves the rectangle, leaving the bottom-left corner at the given \a position. The rectangle's size is unchanged. \sa setBottomLeft(), moveBottom(), moveLeft()*//*! \fn void QRect::moveCenter(const QPoint &position) Moves the rectangle, leaving the center point at the given \a position. The rectangle's size is unchanged. \sa center()*/void QRect::moveCenter(const QPoint &p){ int w = x2 - x1; int h = y2 - y1; x1 = p.x() - w/2; y1 = p.y() - h/2; x2 = x1 + w; y2 = y1 + h;}/*! \fn void QRect::moveBy(int dx, int dy) \compat Moves the rectangle \a dx along the x axis and \a dy along the y axis, relative to the current position. Use the translate() function instead.*//*! \fn void QRect::moveBy(const QPoint &) \compat Use the translate() function instead.*//*! \fn void QRect::moveTo(int x, int y) Moves the rectangle, leaving the top-left corner at the given position (\a x, \a y). The rectangle's size is unchanged. \sa translate(), moveTopLeft()*//*! \fn void QRect::moveTo(const QPoint &position) Moves the rectangle, leaving the top-left corner at the given \a position.*//*! \fn void QRect::translate(int dx, int dy) Moves the rectangle \a dx along the x axis and \a dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down. \sa moveTopLeft(), moveTo(), translated()*//*! \fn void QRect::translate(const QPoint &offset) \overload Moves the rectangle \a{offset}.\l{QPoint::x()}{x()} along the x axis and \a{offset}.\l{QPoint::y()}{y()} along the y axis, relative to the current position.*//*! \fn QRect QRect::translated(int dx, int dy) const Returns a copy of the rectangle that is translated \a dx along the x axis and \a dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down. \sa translate()*//*! \fn QRect QRect::translated(const QPoint &offset) const \overload Returns a copy of the rectangle that is translated \a{offset}.\l{QPoint::x()}{x()} along the x axis and \a{offset}.\l{QPoint::y()}{y()} along the y axis, relative to the current position.*//*! \fn void QRect::setRect(int x, int y, int width, int height) Sets the coordinates of the rectangle's top-left corner to (\a{x}, \a{y}), and its size to the given \a width and \a height. \sa getRect(), setCoords()*//*! \fn void QRect::setCoords(int x1, int y1, int x2, int y2) Sets the coordinates of the rectangle's top-left corner to (\a x1, \a y1), and the coordinates of its bottom-right corner to (\a x2, \a y2). \sa getCoords(), setRect()*//*! \fn void QRect::addCoords(int dx1, int dy1, int dx2, int dy2) \compat Adds \a dx1, \a dy1, \a dx2 and \a dy2 to the existing coordinates of the rectangle respectively. Use the adjust() function instead.*//*! \fn QRect QRect::adjusted(int dx1, int dy1, int dx2, int dy2) const Returns a new rectangle with \a dx1, \a dy1, \a dx2 and \a dy2 added respectively to the existing coordinates of this rectangle. \sa adjust()*//*! \fn void QRect::adjust(int dx1, int dy1, int dx2, int dy2) Adds \a dx1, \a dy1, \a dx2 and \a dy2 respectively to the existing coordinates of the rectangle. \sa adjusted(), setRect()*//*! \fn QSize QRect::size() const Returns the size of the rectangle. \sa setSize(), width(), height()*//*! \fn int QRect::width() const Returns the width of the rectangle. \sa setWidth(), height(), size()*//*! \fn int QRect::height() const Returns the height of the rectangle. \sa setHeight(), width(), size()*//*! \fn void QRect::setWidth(int width) Sets the width of the rectangle to the given \a width. The right edge is changed, but not the left one. \sa width(), setSize()*//*! \fn void QRect::setHeight(int height) Sets the height of the rectangle to the given \a height. The bottom edge is changed, but not the top one. \sa height(), setSize()*//*! \fn void QRect::setSize(const QSize &size) Sets the size of the rectangle to the given \a size. The top-left corner is not moved. \sa size(), setWidth(), setHeight()*//*! \fn bool QRect::contains(const QPoint &point, bool proper) const Returns true if the the given \a point is inside or on the edge of the rectangle, otherwise returns false. If \a proper is true, this function only returns true if the given \a point is \e inside the rectangle (i.e., not on the edge). \sa intersects()*/bool QRect::contains(const QPoint &p, bool proper) const{ QRect r = normalized(); if (proper) return p.x() > r.x1 && p.x() < r.x2 && p.y() > r.y1 && p.y() < r.y2; else return p.x() >= r.x1 && p.x() <= r.x2 && p.y() >= r.y1 && p.y() <= r.y2;}/*! \fn bool QRect::contains(int x, int y, bool proper) const \overload Returns true if the point (\a x, \a y) is inside or on the edge of the rectangle, otherwise returns false. If \a proper is true, this function only returns true if the point is entirely inside the rectangle(not on the edge).*//*! \fn bool QRect::contains(int x, int y) const \overload Returns true if the point (\a x, \a y) is inside this rectangle, otherwise returns false.*//*! \fn bool QRect::contains(const QRect &rectangle, bool proper) const \overload Returns true if the given \a rectangle is inside this rectangle. otherwise returns false. If \a proper is true, this function only returns true if the \a rectangle is entirely inside this rectangle (not on the edge).*/bool QRect::contains(const QRect &r, bool proper) const{ if (isNull() || r.isNull()) return false; QRect r1 = normalized(); QRect r2 = r.normalized(); if (proper) return r2.x1 > r1.x1 && r2.x2 < r1.x2 && r2.y1 > r1.y1 && r2.y2 < r1.y2; else return r2.x1 >= r1.x1 && r2.x2 <= r1.x2 && r2.y1 >= r1.y1 && r2.y2 <= r1.y2;}/*! \fn QRect& QRect::operator|=(const QRect &rectangle) Unites this rectangle with the given \a rectangle. \sa united(), operator|()*//*! \fn QRect& QRect::operator&=(const QRect &rectangle) Intersects this rectangle with the given \a rectangle. \sa intersected(), operator&()*//*! \fn QRect QRect::operator|(const QRect &rectangle) const Returns the bounding rectangle of this rectangle and the given \a rectangle. \sa operator|=(), united()*/QRect QRect::operator|(const QRect &r) const{ if (isNull()) return r; if (r.isNull()) return *this; QRect r1 = normalized(); QRect r2 = r.normalized(); QRect tmp; tmp.x1 = qMin(r1.x1, r2.x1); tmp.x2 = qMax(r1.x2, r2.x2); tmp.y1 = qMin(r1.y1, r2.y1); tmp.y2 = qMax(r1.y2, r2.y2); return tmp;}/*! \fn QRect QRect::unite(const QRect &rectangle) const \obsolete Use united(\a rectangle) instead.*//*! \fn QRect QRect::united(const QRect &rectangle) const \since 4.2 Returns the bounding rectangle of this rectangle and the given \a rectangle. \image qrect-unite.png \sa intersected()*//*! \fn QRect QRect::operator&(const QRect &rectangle) const Returns the intersection of this rectangle and the given \a rectangle. Returns an empty rectangle if there is no intersection. \sa operator&=(), intersected()*/QRect QRect::operator&(const QRect &r) const{ if (isNull() || r.isNull()) return QRect(); QRect r1 = normalized(); QRect r2 = r.normalized(); QRect tmp; tmp.x1 = qMax(r1.x1, r2.x1); tmp.x2 = qMin(r1.x2, r2.x2); tmp.y1 = qMax(r1.y1, r2.y1); tmp.y2 = qMin(r1.y2, r2.y2); return tmp.isEmpty() ? QRect() : tmp;}/*! \fn QRect QRect::intersect(const QRect &rectangle) const \obsolete Use intersected(\a rectangle) instead.*//*! \fn QRect QRect::intersected(const QRect &rectangle) const \since 4.2 Returns the intersection of this rectangle and the given \a rectangle. Note that \c{r.intersected(s)} is equivalent to \c{r & s}. \image qrect-intersect.png \sa intersects(), united(), operator&=()*//*! \fn bool QRect::intersects(const QRect &rectangle) const Returns true if this rectangle intersects with the given \a rectangle (i.e., there is at least one pixel that is within both rectangles), otherwise returns false. The intersection rectangle can be retrieved using the intersected() function. \sa contains()*/bool QRect::intersects(const QRect &r) const{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -