#[repr(C)]pub struct QRect { /* private fields */ }
Expand description
The QRect class defines a rectangle in the plane using integer precision.
C++ class: QRect
.
The QRect class defines a rectangle in the plane using integer precision.
A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of a QRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A QRect 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.
QRect r1(100, 200, 11, 16); QRect r2(QPoint(100, 200), QSize(11, 16));
There is a third constructor that creates a QRect using the top-left and bottom-right coordinates, but we recommend that you avoid using it. The rationale is that for historical reasons the values returned by the bottom() and right() functions deviate from the true bottom-right corner of the rectangle.
The QRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRect 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. The QRect 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:
The isEmpty() function returns true
if left() > right() or top() > bottom(). Note that an empty rectangle is not valid: The isValid() function returns true
if left() <= right() and top() <= bottom(). A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.
Note that due to the way QRect and QRectF are defined, an empty QRect is defined in essentially the same way as QRectF.
Finally, QRect objects can be streamed as well as compared.
Implementations§
source§impl QRect
impl QRect
sourcepub unsafe fn add_assign(
&self,
margins: impl CastInto<Ref<QMargins>>
) -> Ref<QRect>
pub unsafe fn add_assign( &self, margins: impl CastInto<Ref<QMargins>> ) -> Ref<QRect>
Adds the margins to the rectangle, growing it.
Calls C++ function: QRect& QRect::operator+=(const QMargins& margins)
.
Adds the margins to the rectangle, growing it.
This function was introduced in Qt 5.1.
See also marginsAdded(), marginsRemoved(), and operator-=().
sourcepub unsafe fn adjust(&self, x1: c_int, y1: c_int, x2: c_int, y2: c_int)
pub unsafe fn adjust(&self, x1: c_int, y1: c_int, x2: c_int, y2: c_int)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Calls C++ function: void QRect::adjust(int x1, int y1, int x2, int y2)
.
sourcepub unsafe fn adjusted(
&self,
x1: c_int,
y1: c_int,
x2: c_int,
y2: c_int
) -> CppBox<QRect>
pub unsafe fn adjusted( &self, x1: c_int, y1: c_int, x2: c_int, y2: c_int ) -> CppBox<QRect>
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of this rectangle.
Calls C++ function: QRect QRect::adjusted(int x1, int y1, int x2, int y2) const
.
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of this rectangle.
See also adjust().
sourcepub unsafe fn bit_and_assign(&self, r: impl CastInto<Ref<QRect>>) -> Ref<QRect>
pub unsafe fn bit_and_assign(&self, r: impl CastInto<Ref<QRect>>) -> Ref<QRect>
Intersects this rectangle with the given rectangle.
Calls C++ function: QRect& QRect::operator&=(const QRect& r)
.
Intersects this rectangle with the given rectangle.
See also intersected() and operator&().
sourcepub unsafe fn bit_or_assign(&self, r: impl CastInto<Ref<QRect>>) -> Ref<QRect>
pub unsafe fn bit_or_assign(&self, r: impl CastInto<Ref<QRect>>) -> Ref<QRect>
Unites this rectangle with the given rectangle.
Calls C++ function: QRect& QRect::operator|=(const QRect& r)
.
sourcepub unsafe fn bottom(&self) -> c_int
pub unsafe fn bottom(&self) -> c_int
Returns the y-coordinate of the rectangle's bottom edge.
Calls C++ function: int QRect::bottom() const
.
Returns the y-coordinate of the rectangle’s bottom edge.
Note that for historical reasons this function returns top() + height() - 1; use y() + height() to retrieve the true y-coordinate.
See also setBottom(), bottomLeft(), and bottomRight().
sourcepub unsafe fn bottom_left(&self) -> CppBox<QPoint>
pub unsafe fn bottom_left(&self) -> CppBox<QPoint>
sourcepub unsafe fn bottom_right(&self) -> CppBox<QPoint>
pub unsafe fn bottom_right(&self) -> CppBox<QPoint>
Returns the position of the rectangle's bottom-right corner.
Calls C++ function: QPoint QRect::bottomRight() const
.
sourcepub unsafe fn center(&self) -> CppBox<QPoint>
pub unsafe fn center(&self) -> CppBox<QPoint>
Returns the center point of the rectangle.
Calls C++ function: QPoint QRect::center() const
.
Returns the center point of the rectangle.
See also moveCenter().
sourcepub unsafe fn contains_q_rect_bool(
&self,
r: impl CastInto<Ref<QRect>>,
proper: bool
) -> bool
pub unsafe fn contains_q_rect_bool( &self, r: impl CastInto<Ref<QRect>>, proper: bool ) -> bool
This is an overloaded function.
Calls C++ function: bool QRect::contains(const QRect& r, bool proper = …) const
.
This is an overloaded function.
Returns true
if the given rectangle is inside this rectangle. otherwise returns false
. If proper is true, this function only returns true
if the rectangle is entirely inside this rectangle (not on the edge).
sourcepub unsafe fn contains_q_point_bool(
&self,
p: impl CastInto<Ref<QPoint>>,
proper: bool
) -> bool
pub unsafe fn contains_q_point_bool( &self, p: impl CastInto<Ref<QPoint>>, proper: bool ) -> bool
Returns true
if the given point is inside or on the edge of the rectangle, otherwise returns false
. If proper is true, this function only returns true
if the given point is inside the rectangle (i.e., not on the edge).
Calls C++ function: bool QRect::contains(const QPoint& p, bool proper = …) const
.
Returns true
if the given point is inside or on the edge of the rectangle, otherwise returns false
. If proper is true, this function only returns true
if the given point is inside the rectangle (i.e., not on the edge).
See also intersects().
sourcepub unsafe fn contains_2_int(&self, x: c_int, y: c_int) -> bool
pub unsafe fn contains_2_int(&self, x: c_int, y: c_int) -> bool
This is an overloaded function.
Calls C++ function: bool QRect::contains(int x, int y) const
.
This is an overloaded function.
Returns true
if the point (x, y) is inside this rectangle, otherwise returns false
.
sourcepub unsafe fn contains_2_int_bool(
&self,
x: c_int,
y: c_int,
proper: bool
) -> bool
pub unsafe fn contains_2_int_bool( &self, x: c_int, y: c_int, proper: bool ) -> bool
This is an overloaded function.
Calls C++ function: bool QRect::contains(int x, int y, bool proper) 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
. If proper is true, this function only returns true
if the point is entirely inside the rectangle(not on the edge).
sourcepub unsafe fn contains_q_rect(&self, r: impl CastInto<Ref<QRect>>) -> bool
pub unsafe fn contains_q_rect(&self, r: impl CastInto<Ref<QRect>>) -> bool
This is an overloaded function.
Calls C++ function: bool QRect::contains(const QRect& r) const
.
This is an overloaded function.
Returns true
if the given rectangle is inside this rectangle. otherwise returns false
. If proper is true, this function only returns true
if the rectangle is entirely inside this rectangle (not on the edge).
sourcepub unsafe fn contains_q_point(&self, p: impl CastInto<Ref<QPoint>>) -> bool
pub unsafe fn contains_q_point(&self, p: impl CastInto<Ref<QPoint>>) -> bool
Returns true
if the given point is inside or on the edge of the rectangle, otherwise returns false
. If proper is true, this function only returns true
if the given point is inside the rectangle (i.e., not on the edge).
Calls C++ function: bool QRect::contains(const QPoint& p) const
.
Returns true
if the given point is inside or on the edge of the rectangle, otherwise returns false
. If proper is true, this function only returns true
if the given point is inside the rectangle (i.e., not on the edge).
See also intersects().
sourcepub unsafe fn copy_from(&self, other: impl CastInto<Ref<QRect>>) -> Ref<QRect>
pub unsafe fn copy_from(&self, other: impl CastInto<Ref<QRect>>) -> Ref<QRect>
The QRect class defines a rectangle in the plane using integer precision.
Calls C++ function: QRect& QRect::operator=(const QRect& other)
.
The QRect class defines a rectangle in the plane using integer precision.
A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of a QRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A QRect 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.
QRect r1(100, 200, 11, 16); QRect r2(QPoint(100, 200), QSize(11, 16));
There is a third constructor that creates a QRect using the top-left and bottom-right coordinates, but we recommend that you avoid using it. The rationale is that for historical reasons the values returned by the bottom() and right() functions deviate from the true bottom-right corner of the rectangle.
The QRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRect 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. The QRect 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:
The isEmpty() function returns true
if left() > right() or top() > bottom(). Note that an empty rectangle is not valid: The isValid() function returns true
if left() <= right() and top() <= bottom(). A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.
Note that due to the way QRect and QRectF are defined, an empty QRect is defined in essentially the same way as QRectF.
Finally, QRect objects can be streamed as well as compared.
sourcepub unsafe fn get_coords(
&self,
x1: *mut c_int,
y1: *mut c_int,
x2: *mut c_int,
y2: *mut c_int
)
pub unsafe fn get_coords( &self, x1: *mut c_int, y1: *mut c_int, x2: *mut c_int, y2: *mut c_int )
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.
Calls C++ function: void QRect::getCoords(int* x1, int* y1, int* x2, int* y2) const
.
sourcepub unsafe fn get_rect(
&self,
x: *mut c_int,
y: *mut c_int,
w: *mut c_int,
h: *mut c_int
)
pub unsafe fn get_rect( &self, x: *mut c_int, y: *mut c_int, w: *mut c_int, h: *mut c_int )
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height.
Calls C++ function: void QRect::getRect(int* x, int* y, int* w, int* h) const
.
sourcepub unsafe fn height(&self) -> c_int
pub unsafe fn height(&self) -> c_int
Returns the height of the rectangle.
Calls C++ function: int QRect::height() const
.
sourcepub unsafe fn intersected(
&self,
other: impl CastInto<Ref<QRect>>
) -> CppBox<QRect>
pub unsafe fn intersected( &self, other: impl CastInto<Ref<QRect>> ) -> CppBox<QRect>
Returns the intersection of this rectangle and the given rectangle. Note that r.intersected(s)
is equivalent to r & s
.
Calls C++ function: QRect QRect::intersected(const QRect& other) const
.
Returns the intersection of this rectangle and the given rectangle. Note that r.intersected(s)
is equivalent to r & s
.
This function was introduced in Qt 4.2.
See also intersects(), united(), and operator&=().
sourcepub unsafe fn intersects(&self, r: impl CastInto<Ref<QRect>>) -> bool
pub unsafe fn intersects(&self, r: impl CastInto<Ref<QRect>>) -> bool
Returns true
if this rectangle intersects with the given rectangle (i.e., there is at least one pixel that is within both rectangles), otherwise returns false
.
Calls C++ function: bool QRect::intersects(const QRect& r) const
.
Returns true
if this rectangle intersects with the given 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.
See also contains().
sourcepub unsafe fn is_empty(&self) -> bool
pub unsafe fn is_empty(&self) -> bool
Returns true
if the rectangle is empty, otherwise returns false
.
Calls C++ function: bool QRect::isEmpty() const
.
Returns true
if the rectangle is empty, otherwise returns false
.
An empty rectangle has a left() > right() or top() > bottom(). An empty rectangle is not valid (i.e., isEmpty() == !isValid()).
Use the normalized() function to retrieve a rectangle where the corners are swapped.
See also isNull(), isValid(), and normalized().
sourcepub unsafe fn is_null(&self) -> bool
pub unsafe fn is_null(&self) -> bool
Returns true
if the rectangle is a null rectangle, otherwise returns false
.
Calls C++ function: bool QRect::isNull() const
.
sourcepub unsafe fn is_valid(&self) -> bool
pub unsafe fn is_valid(&self) -> bool
Returns true
if the rectangle is valid, otherwise returns false
.
Calls C++ function: bool QRect::isValid() const
.
Returns true
if the rectangle is valid, otherwise returns false
.
A valid rectangle has a left() <= right() and top() <= bottom(). Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).
See also isNull(), isEmpty(), and normalized().
sourcepub unsafe fn left(&self) -> c_int
pub unsafe fn left(&self) -> c_int
Returns the x-coordinate of the rectangle's left edge. Equivalent to x().
Calls C++ function: int QRect::left() const
.
Returns the x-coordinate of the rectangle’s left edge. Equivalent to x().
See also setLeft(), topLeft(), and bottomLeft().
sourcepub unsafe fn margins_added(
&self,
margins: impl CastInto<Ref<QMargins>>
) -> CppBox<QRect>
pub unsafe fn margins_added( &self, margins: impl CastInto<Ref<QMargins>> ) -> CppBox<QRect>
Returns a rectangle grown by the margins.
Calls C++ function: QRect QRect::marginsAdded(const QMargins& margins) const
.
Returns a rectangle grown by the margins.
This function was introduced in Qt 5.1.
See also operator+=(), marginsRemoved(), and operator-=().
sourcepub unsafe fn margins_removed(
&self,
margins: impl CastInto<Ref<QMargins>>
) -> CppBox<QRect>
pub unsafe fn margins_removed( &self, margins: impl CastInto<Ref<QMargins>> ) -> CppBox<QRect>
Removes the margins from the rectangle, shrinking it.
Calls C++ function: QRect QRect::marginsRemoved(const QMargins& margins) const
.
Removes the margins from the rectangle, shrinking it.
This function was introduced in Qt 5.1.
See also marginsAdded(), operator+=(), and operator-=().
sourcepub unsafe fn move_bottom(&self, pos: c_int)
pub unsafe fn move_bottom(&self, pos: c_int)
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveBottom(int pos)
.
sourcepub unsafe fn move_bottom_left(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn move_bottom_left(&self, p: impl CastInto<Ref<QPoint>>)
Moves the rectangle, leaving the bottom-left corner at the given position. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveBottomLeft(const QPoint& p)
.
Moves the rectangle, leaving the bottom-left corner at the given position. The rectangle’s size is unchanged.
See also setBottomLeft(), moveBottom(), and moveLeft().
sourcepub unsafe fn move_bottom_right(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn move_bottom_right(&self, p: impl CastInto<Ref<QPoint>>)
Moves the rectangle, leaving the bottom-right corner at the given position. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveBottomRight(const QPoint& p)
.
Moves the rectangle, leaving the bottom-right corner at the given position. The rectangle’s size is unchanged.
See also setBottomRight(), moveRight(), and moveBottom().
sourcepub unsafe fn move_center(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn move_center(&self, p: impl CastInto<Ref<QPoint>>)
Moves the rectangle, leaving the center point at the given position. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveCenter(const QPoint& p)
.
Moves the rectangle, leaving the center point at the given position. The rectangle’s size is unchanged.
See also center().
sourcepub unsafe fn move_left(&self, pos: c_int)
pub unsafe fn move_left(&self, pos: c_int)
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveLeft(int pos)
.
sourcepub unsafe fn move_right(&self, pos: c_int)
pub unsafe fn move_right(&self, pos: c_int)
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveRight(int pos)
.
sourcepub unsafe fn move_to_2a(&self, x: c_int, t: c_int)
pub unsafe fn move_to_2a(&self, x: c_int, t: c_int)
Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged.
Calls C++ function: void QRect::moveTo(int x, int t)
.
Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle’s size is unchanged.
See also translate() and moveTopLeft().
sourcepub unsafe fn move_to_1a(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn move_to_1a(&self, p: impl CastInto<Ref<QPoint>>)
Moves the rectangle, leaving the top-left corner at the given position.
Calls C++ function: void QRect::moveTo(const QPoint& p)
.
Moves the rectangle, leaving the top-left corner at the given position.
sourcepub unsafe fn move_top(&self, pos: c_int)
pub unsafe fn move_top(&self, pos: c_int)
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveTop(int pos)
.
Moves the rectangle vertically, leaving the rectangle’s top edge at the given y coordinate. The rectangle’s size is unchanged.
See also top(), setTop(), and moveBottom().
sourcepub unsafe fn move_top_left(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn move_top_left(&self, p: impl CastInto<Ref<QPoint>>)
Moves the rectangle, leaving the top-left corner at the given position. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveTopLeft(const QPoint& p)
.
Moves the rectangle, leaving the top-left corner at the given position. The rectangle’s size is unchanged.
See also setTopLeft(), moveTop(), and moveLeft().
sourcepub unsafe fn move_top_right(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn move_top_right(&self, p: impl CastInto<Ref<QPoint>>)
Moves the rectangle, leaving the top-right corner at the given position. The rectangle's size is unchanged.
Calls C++ function: void QRect::moveTopRight(const QPoint& p)
.
Moves the rectangle, leaving the top-right corner at the given position. The rectangle’s size is unchanged.
See also setTopRight(), moveTop(), and moveRight().
sourcepub unsafe fn new() -> CppBox<QRect>
pub unsafe fn new() -> CppBox<QRect>
Constructs a null rectangle.
Calls C++ function: [constructor] void QRect::QRect()
.
Constructs a null rectangle.
See also isNull().
sourcepub unsafe fn from_2_q_point(
topleft: impl CastInto<Ref<QPoint>>,
bottomright: impl CastInto<Ref<QPoint>>
) -> CppBox<QRect>
pub unsafe fn from_2_q_point( topleft: impl CastInto<Ref<QPoint>>, bottomright: impl CastInto<Ref<QPoint>> ) -> CppBox<QRect>
Constructs a rectangle with the given topLeft and bottomRight corners.
Calls C++ function: [constructor] void QRect::QRect(const QPoint& topleft, const QPoint& bottomright)
.
Constructs a rectangle with the given topLeft and bottomRight corners.
See also setTopLeft() and setBottomRight().
sourcepub unsafe fn from_q_point_q_size(
topleft: impl CastInto<Ref<QPoint>>,
size: impl CastInto<Ref<QSize>>
) -> CppBox<QRect>
pub unsafe fn from_q_point_q_size( topleft: impl CastInto<Ref<QPoint>>, size: impl CastInto<Ref<QSize>> ) -> CppBox<QRect>
Constructs a rectangle with the given topLeft corner and the given size.
Calls C++ function: [constructor] void QRect::QRect(const QPoint& topleft, const QSize& size)
.
Constructs a rectangle with the given topLeft corner and the given size.
See also setTopLeft() and setSize().
sourcepub unsafe fn from_4_int(
left: c_int,
top: c_int,
width: c_int,
height: c_int
) -> CppBox<QRect>
pub unsafe fn from_4_int( left: c_int, top: c_int, width: c_int, height: c_int ) -> CppBox<QRect>
Constructs a rectangle with (x, y) as its top-left corner and the given width and height.
Calls C++ function: [constructor] void QRect::QRect(int left, int top, int width, int height)
.
Constructs a rectangle with (x, y) as its top-left corner and the given width and height.
See also setRect().
sourcepub unsafe fn new_copy(other: impl CastInto<Ref<QRect>>) -> CppBox<QRect>
pub unsafe fn new_copy(other: impl CastInto<Ref<QRect>>) -> CppBox<QRect>
The QRect class defines a rectangle in the plane using integer precision.
Calls C++ function: [constructor] void QRect::QRect(const QRect& other)
.
The QRect class defines a rectangle in the plane using integer precision.
A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of a QRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A QRect 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.
QRect r1(100, 200, 11, 16); QRect r2(QPoint(100, 200), QSize(11, 16));
There is a third constructor that creates a QRect using the top-left and bottom-right coordinates, but we recommend that you avoid using it. The rationale is that for historical reasons the values returned by the bottom() and right() functions deviate from the true bottom-right corner of the rectangle.
The QRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRect 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. The QRect 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:
The isEmpty() function returns true
if left() > right() or top() > bottom(). Note that an empty rectangle is not valid: The isValid() function returns true
if left() <= right() and top() <= bottom(). A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.
Note that due to the way QRect and QRectF are defined, an empty QRect is defined in essentially the same way as QRectF.
Finally, QRect objects can be streamed as well as compared.
sourcepub unsafe fn normalized(&self) -> CppBox<QRect>
pub unsafe fn normalized(&self) -> CppBox<QRect>
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height.
Calls C++ function: QRect QRect::normalized() const
.
sourcepub unsafe fn right(&self) -> c_int
pub unsafe fn right(&self) -> c_int
Returns the x-coordinate of the rectangle's right edge.
Calls C++ function: int QRect::right() const
.
sourcepub unsafe fn set_bottom(&self, pos: c_int)
pub unsafe fn set_bottom(&self, pos: c_int)
Sets the bottom edge of the rectangle to the given y coordinate. May change the height, but will never change the top edge of the rectangle.
Calls C++ function: void QRect::setBottom(int pos)
.
Sets the bottom edge of the rectangle to the given y coordinate. May change the height, but will never change the top edge of the rectangle.
See also bottom() and moveBottom().
sourcepub unsafe fn set_bottom_left(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn set_bottom_left(&self, p: impl CastInto<Ref<QPoint>>)
Set the bottom-left corner of the rectangle to the given position. May change the size, but will never change the top-right corner of the rectangle.
Calls C++ function: void QRect::setBottomLeft(const QPoint& p)
.
Set the bottom-left corner of the rectangle to the given position. May change the size, but will never change the top-right corner of the rectangle.
See also bottomLeft() and moveBottomLeft().
sourcepub unsafe fn set_bottom_right(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn set_bottom_right(&self, p: impl CastInto<Ref<QPoint>>)
Set the bottom-right corner of the rectangle to the given position. May change the size, but will never change the top-left corner of the rectangle.
Calls C++ function: void QRect::setBottomRight(const QPoint& p)
.
Set the bottom-right corner of the rectangle to the given position. May change the size, but will never change the top-left corner of the rectangle.
See also bottomRight() and moveBottomRight().
sourcepub unsafe fn set_coords(&self, x1: c_int, y1: c_int, x2: c_int, y2: c_int)
pub unsafe fn set_coords(&self, x1: c_int, y1: c_int, x2: c_int, y2: c_int)
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its bottom-right corner to (x2, y2).
Calls C++ function: void QRect::setCoords(int x1, int y1, int x2, int y2)
.
sourcepub unsafe fn set_height(&self, h: c_int)
pub unsafe fn set_height(&self, h: c_int)
Sets the height of the rectangle to the given height. The bottom edge is changed, but not the top one.
Calls C++ function: void QRect::setHeight(int h)
.
sourcepub unsafe fn set_left(&self, pos: c_int)
pub unsafe fn set_left(&self, pos: c_int)
Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.
Calls C++ function: void QRect::setLeft(int pos)
.
sourcepub unsafe fn set_rect(&self, x: c_int, y: c_int, w: c_int, h: c_int)
pub unsafe fn set_rect(&self, x: c_int, y: c_int, w: c_int, h: c_int)
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width and height.
Calls C++ function: void QRect::setRect(int x, int y, int w, int h)
.
sourcepub unsafe fn set_right(&self, pos: c_int)
pub unsafe fn set_right(&self, pos: c_int)
Sets the right edge of the rectangle to the given x coordinate. May change the width, but will never change the left edge of the rectangle.
Calls C++ function: void QRect::setRight(int pos)
.
sourcepub unsafe fn set_size(&self, s: impl CastInto<Ref<QSize>>)
pub unsafe fn set_size(&self, s: impl CastInto<Ref<QSize>>)
Sets the size of the rectangle to the given size. The top-left corner is not moved.
Calls C++ function: void QRect::setSize(const QSize& s)
.
sourcepub unsafe fn set_top(&self, pos: c_int)
pub unsafe fn set_top(&self, pos: c_int)
Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.
Calls C++ function: void QRect::setTop(int pos)
.
sourcepub unsafe fn set_top_left(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn set_top_left(&self, p: impl CastInto<Ref<QPoint>>)
Set the top-left corner of the rectangle to the given position. May change the size, but will never change the bottom-right corner of the rectangle.
Calls C++ function: void QRect::setTopLeft(const QPoint& p)
.
Set the top-left corner of the rectangle to the given position. May change the size, but will never change the bottom-right corner of the rectangle.
See also topLeft() and moveTopLeft().
sourcepub unsafe fn set_top_right(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn set_top_right(&self, p: impl CastInto<Ref<QPoint>>)
Set the top-right corner of the rectangle to the given position. May change the size, but will never change the bottom-left corner of the rectangle.
Calls C++ function: void QRect::setTopRight(const QPoint& p)
.
Set the top-right corner of the rectangle to the given position. May change the size, but will never change the bottom-left corner of the rectangle.
See also topRight() and moveTopRight().
sourcepub unsafe fn set_width(&self, w: c_int)
pub unsafe fn set_width(&self, w: c_int)
Sets the width of the rectangle to the given width. The right edge is changed, but not the left one.
Calls C++ function: void QRect::setWidth(int w)
.
sourcepub unsafe fn set_x(&self, x: c_int)
pub unsafe fn set_x(&self, x: c_int)
Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.
Calls C++ function: void QRect::setX(int x)
.
Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.
Equivalent to setLeft().
See also x(), setY(), and setTopLeft().
sourcepub unsafe fn set_y(&self, y: c_int)
pub unsafe fn set_y(&self, y: c_int)
Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.
Calls C++ function: void QRect::setY(int y)
.
Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.
Equivalent to setTop().
See also y(), setX(), and setTopLeft().
sourcepub unsafe fn size(&self) -> CppBox<QSize>
pub unsafe fn size(&self) -> CppBox<QSize>
Returns the size of the rectangle.
Calls C++ function: QSize QRect::size() const
.
sourcepub unsafe fn sub_assign(
&self,
margins: impl CastInto<Ref<QMargins>>
) -> Ref<QRect>
pub unsafe fn sub_assign( &self, margins: impl CastInto<Ref<QMargins>> ) -> Ref<QRect>
Returns a rectangle shrunk by the margins.
Calls C++ function: QRect& QRect::operator-=(const QMargins& margins)
.
Returns a rectangle shrunk by the margins.
This function was introduced in Qt 5.1.
See also marginsRemoved(), operator+=(), and marginsAdded().
sourcepub unsafe fn top_left(&self) -> CppBox<QPoint>
pub unsafe fn top_left(&self) -> CppBox<QPoint>
Returns the position of the rectangle's top-left corner.
Calls C++ function: QPoint QRect::topLeft() const
.
Returns the position of the rectangle’s top-left corner.
See also setTopLeft(), top(), and left().
sourcepub unsafe fn top_right(&self) -> CppBox<QPoint>
pub unsafe fn top_right(&self) -> CppBox<QPoint>
Returns the position of the rectangle's top-right corner.
Calls C++ function: QPoint QRect::topRight() const
.
sourcepub unsafe fn translate_2a(&self, dx: c_int, dy: c_int)
pub unsafe fn translate_2a(&self, dx: c_int, dy: c_int)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
Calls C++ function: void QRect::translate(int dx, int dy)
.
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
See also moveTopLeft(), moveTo(), and translated().
sourcepub unsafe fn translate_1a(&self, p: impl CastInto<Ref<QPoint>>)
pub unsafe fn translate_1a(&self, p: impl CastInto<Ref<QPoint>>)
This is an overloaded function.
Calls C++ function: void QRect::translate(const QPoint& p)
.
sourcepub unsafe fn translated_2a(&self, dx: c_int, dy: c_int) -> CppBox<QRect>
pub unsafe fn translated_2a(&self, dx: c_int, dy: c_int) -> CppBox<QRect>
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
Calls C++ function: QRect QRect::translated(int dx, int dy) const
.
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
See also translate().
sourcepub unsafe fn translated_1a(
&self,
p: impl CastInto<Ref<QPoint>>
) -> CppBox<QRect>
pub unsafe fn translated_1a( &self, p: impl CastInto<Ref<QPoint>> ) -> CppBox<QRect>
This is an overloaded function.
Calls C++ function: QRect QRect::translated(const QPoint& p) const
.
sourcepub unsafe fn transposed(&self) -> CppBox<QRect>
pub unsafe fn transposed(&self) -> CppBox<QRect>
Returns a copy of the rectangle that has its width and height exchanged:
Calls C++ function: QRect QRect::transposed() const
.
Returns a copy of the rectangle that has its width and height exchanged:
QRect r = {15, 51, 42, 24}; r = r.transposed(); // r == {15, 51, 24, 42}
This function was introduced in Qt 5.7.
See also QSize::transposed().
sourcepub unsafe fn united(&self, other: impl CastInto<Ref<QRect>>) -> CppBox<QRect>
pub unsafe fn united(&self, other: impl CastInto<Ref<QRect>>) -> CppBox<QRect>
Returns the bounding rectangle of this rectangle and the given rectangle.
Calls C++ function: QRect QRect::united(const QRect& other) const
.
Returns the bounding rectangle of this rectangle and the given rectangle.
This function was introduced in Qt 4.2.
See also intersected().
sourcepub unsafe fn width(&self) -> c_int
pub unsafe fn width(&self) -> c_int
Returns the width of the rectangle.
Calls C++ function: int QRect::width() const
.
Trait Implementations§
source§impl BitAnd<Ref<QRect>> for &QRect
impl BitAnd<Ref<QRect>> for &QRect
source§fn bitand(self, r: Ref<QRect>) -> CppBox<QRect>
fn bitand(self, r: Ref<QRect>) -> CppBox<QRect>
Returns the intersection of this rectangle and the given rectangle. Returns an empty rectangle if there is no intersection.
Calls C++ function: QRect QRect::operator&(const QRect& r) const
.
Returns the intersection of this rectangle and the given rectangle. Returns an empty rectangle if there is no intersection.
See also operator&=() and intersected().
source§impl BitOr<Ref<QRect>> for &QRect
impl BitOr<Ref<QRect>> for &QRect
source§fn bitor(self, r: Ref<QRect>) -> CppBox<QRect>
fn bitor(self, r: Ref<QRect>) -> CppBox<QRect>
Returns the bounding rectangle of this rectangle and the given rectangle.
Calls C++ function: QRect QRect::operator|(const QRect& r) const
.
Returns the bounding rectangle of this rectangle and the given rectangle.
See also operator|=() and united().
source§impl CppDeletable for QRect
impl CppDeletable for QRect
source§unsafe fn delete(&self)
unsafe fn delete(&self)
The QRect class defines a rectangle in the plane using integer precision.
Calls C++ function: [destructor] void QRect::~QRect()
.
The QRect class defines a rectangle in the plane using integer precision.
A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of a QRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A QRect 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.
QRect r1(100, 200, 11, 16); QRect r2(QPoint(100, 200), QSize(11, 16));
There is a third constructor that creates a QRect using the top-left and bottom-right coordinates, but we recommend that you avoid using it. The rationale is that for historical reasons the values returned by the bottom() and right() functions deviate from the true bottom-right corner of the rectangle.
The QRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRect 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. The QRect 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:
The isEmpty() function returns true
if left() > right() or top() > bottom(). Note that an empty rectangle is not valid: The isValid() function returns true
if left() <= right() and top() <= bottom(). A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.
Note that due to the way QRect and QRectF are defined, an empty QRect is defined in essentially the same way as QRectF.
Finally, QRect objects can be streamed as well as compared.
source§impl PartialEq<Ref<QRect>> for QRect
impl PartialEq<Ref<QRect>> for QRect
source§fn eq(&self, arg2: &Ref<QRect>) -> bool
fn eq(&self, arg2: &Ref<QRect>) -> bool
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
Calls C++ function: bool operator==(const QRect& arg1, const QRect& arg2)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator==(QChar c1, QChar c2)
:
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.