Constraints
QRect
is limited to the minimum and maximum values for the int
type. Operations on a QRect
that could potentially result in values outside this range will result in undefined behavior.
See also
QRectF
QRegion
Constructs a rectangle with the given topLeft
and bottomRight
corners, both included.
If bottomRight
is to higher and to the left of topLeft
, the rectangle defined is instead non-inclusive of the corners.
To ensure both points are included regardless of relative order, use span()
.
See also
setTopLeft()
setBottomRight()
span()
Constructs a rectangle with (x
, y
) as its top-left corner and the given width
and height
.
See also
setRect()
Returns a new rectangle with dx1
, dy1
, dx2
and dy2
added respectively to the existing coordinates of this rectangle.
See also
adjust()
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()
bottomRight()
Returns the position of the rectangle’s bottom-left corner. Note that for historical reasons this function returns QPoint
( left()
, top()
+ height()
- 1).
See also
setBottomLeft()
bottom()
left()
Returns the position of the rectangle’s bottom-right corner.
Note that for historical reasons this function returns QPoint
( left()
+ width()
-1, top()
+ height()
- 1).
See also
setBottomRight()
bottom()
right()
This is an overloaded function.
Returns true
if the point (x
, y
) is inside this rectangle, otherwise returns false
.
contains(x, y, proper)
Parameters:
x – int
y – int
proper – bool
Return type:
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).
contains(r[, proper=false])
Parameters:
r – QRect
proper – bool
Return type:
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).
contains(p[, proper=false])
Parameters:
p – QPoint
proper – bool
Return type:
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()
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 also
setCoords()
getRect()
Extracts the position of the rectangle’s top-left corner to *``x`` and *``y``, and its dimensions to *``width`` and *``height``.
See also
setRect()
getCoords()
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()
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()
normalized()
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 (i.e., right()
== left()
- 1 and bottom()
== top()
- 1). A null rectangle is also empty, and hence is not valid.
See also
isEmpty()
isValid()
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()
normalized()
Moves the rectangle vertically, leaving the rectangle’s bottom edge at the given y
coordinate. The rectangle’s size is unchanged.
See also
bottom()
setBottom()
moveTop()
Moves the rectangle, leaving the bottom-left corner at the given position
. The rectangle’s size is unchanged.
See also
setBottomLeft()
moveBottom()
moveLeft()
Moves the rectangle, leaving the bottom-right corner at the given position
. The rectangle’s size is unchanged.
See also
setBottomRight()
moveRight()
moveBottom()
Moves the rectangle, leaving the center point at the given position
. The rectangle’s size is unchanged.
See also
center()
Moves the rectangle horizontally, leaving the rectangle’s left edge at the given x
coordinate. The rectangle’s size is unchanged.
See also
left()
setLeft()
moveRight()
Moves the rectangle horizontally, leaving the rectangle’s right edge at the given x
coordinate. The rectangle’s size is unchanged.
See also
right()
setRight()
moveLeft()
Moves the rectangle, leaving the top-left corner at the given position (x
, y
). The rectangle’s size is unchanged.
See also
translate()
moveTopLeft()
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()
moveBottom()
Moves the rectangle, leaving the top-left corner at the given position
. The rectangle’s size is unchanged.
See also
setTopLeft()
moveTop()
moveLeft()
Moves the rectangle, leaving the top-right corner at the given position
. The rectangle’s size is unchanged.
See also
setTopRight()
moveTop()
moveRight()
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. The corners are at the same time changed from being non-inclusive to inclusive.
See also
isValid()
isEmpty()
Returns the intersection of this rectangle and the given rectangle
. Returns an empty rectangle if there is no intersection.
See also
operator&=()
intersected()
Returns the x-coordinate of the rectangle’s right edge.
Note that for historical reasons this function returns left()
+ width()
- 1; use x()
+ width()
to retrieve the true x-coordinate.
See also
setRight()
topRight()
bottomRight()
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()
moveBottom()
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()
moveBottomLeft()
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()
moveBottomRight()
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 also
getCoords()
setRect()
Sets the height of the rectangle to the given height
. The bottom edge is changed, but not the top one.
See also
height()
setSize()
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 setX()
.
See also
left()
moveLeft()
Sets the coordinates of the rectangle’s top-left corner to (x
, y
), and its size to the given width
and height
.
See also
getRect()
setCoords()
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.
See also
right()
moveRight()
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 setY()
.
See also
top()
moveTop()
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()
moveTopLeft()
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()
moveTopRight()
Sets the width of the rectangle to the given width
. The right edge is changed, but not the left one.
See also
width()
setSize()
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()
setTopLeft()
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()
setTopLeft()
Returns a rectangle spanning the two points p1
and p2
, including both and everything in between.
toRectF()
Return type:
QRectF
This function, like the QRectF
( QRect
) constructor, preserves the size()
of the rectangle, not its bottomRight()
corner.
See also
toRect()
Returns the position of the rectangle’s top-right corner.
Note that for historical reasons this function returns QPoint
( left()
+ width()
-1, top()
).
See also
setTopRight()
top()
right()
This is an overloaded function.
Moves the rectangle offset
. x()
along the x axis and offset
. y()
along the y axis, relative to the current position.
translate(dx, dy)
Parameters:
dx – int
dy – 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.
See also
moveTopLeft()
moveTo()
translated()
This is an overloaded function.
Returns a copy of the rectangle that is translated offset
. x()
along the x axis and offset
. y()
along the y axis, relative to the current position.
translated(dx, dy)
Parameters:
dx – int
dy – int
Return type:
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.
See also
translate()
Warning
This section contains snippets that were automatically
translated from C++ to Python and may contain errors.
Returns a copy of the rectangle that has its width and height exchanged: