- class QSize¶
The
QSize
class defines the size of a two-dimensional object using integer point precision. More…Synopsis¶
Methods¶
def
__init__()
def
__reduce__()
def
__repr__()
def
boundedTo()
def
expandedTo()
def
grownBy()
def
height()
def
isEmpty()
def
isNull()
def
isValid()
def
__ne__()
def
__mul__()
def
__imul__()
def
__add__()
def
__iadd__()
def
__sub__()
def
__isub__()
def
__div__()
def
operator/=()
def
__eq__()
def
scale()
def
scaled()
def
setHeight()
def
setWidth()
def
shrunkBy()
def
toSizeF()
def
toTuple()
def
transpose()
def
transposed()
def
width()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
A size is specified by a
width()
and aheight()
. It can be set in the constructor and changed using thesetWidth()
,setHeight()
, orscale()
functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using therwidth()
andrheight()
functions. Finally, the width and height can be swapped using thetranspose()
function.The
isValid()
function determines if a size is valid (a valid size has both width and height greater than or equal to zero). TheisEmpty()
function returnstrue
if either of the width and height is less than, or equal to, zero, while theisNull()
function returnstrue
only if both the width and the height is zero.Use the
expandedTo()
function to retrieve a size which holds the maximum height and width of this size and a given size. Similarly, theboundedTo()
function returns a size which holds the minimum height and width of this size and a given size.QSize
objects can be streamed as well as compared.- __init__()¶
Constructs a size with an invalid width and height (i.e.,
isValid()
returnsfalse
).See also
- __init__(w, h)
- Parameters:
w – int
h – int
Constructs a size with the given
width
andheight
.See also
- __reduce__()¶
- Return type:
str
- __repr__()¶
- Return type:
str
Returns a size holding the minimum width and height of this size and the given
otherSize
.See also
Returns a size holding the maximum width and height of this size and the given
otherSize
.See also
- height()¶
- Return type:
int
Returns the height.
See also
- isEmpty()¶
- Return type:
bool
Returns
true
if either of the width and height is less than or equal to 0; otherwise returnsfalse
.- isNull()¶
- Return type:
bool
Returns
true
if both the width and height is 0; otherwise returns false.- isValid()¶
- Return type:
bool
Returns
true
if both the width and height is equal to or greater than 0; otherwise returnsfalse
.Returns
true
iflhs
andrhs
are different; otherwise returnsfalse
.- __ne__(rhs)
- Parameters:
rhs –
QSizeF
- Return type:
bool
This is an overloaded function.
Multiplies the given
size
by the givenfactor
, and returns the result rounded to the nearest integer.- __mul__(c)
- Parameters:
c – float
- Return type:
Multiplies the given
size
by the givenfactor
, and returns the result rounded to the nearest integer.See also
This is an overloaded function.
Multiplies both the width and height by the given
factor
, and returns a reference to the size.Note that the result is rounded to the nearest integer.
See also
Returns the sum of
s1
ands2
; each component is added separately.Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Adds the given
size
to this size, and returns a reference to this size. For example:s = QSize( 3, 7) r = QSize(-1, 4) s += r # s becomes (2,11)
Returns
s2
subtracted froms1
; each component is subtracted separately.Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Subtracts the given
size
from this size, and returns a reference to this size. For example:s = QSize( 3, 7) r = QSize(-1, 4) s -= r # s becomes (4,3)
This is an overloaded function.
Divides the given
size
by the givendivisor
, and returns the result rounded to the nearest integer.See also
- operator/=(c)
- Parameters:
c – float
- Return type:
This is an overloaded function.
Divides both the width and height by the given
divisor
, and returns a reference to the size.Note that the result is rounded to the nearest integer.
See also
Returns
true
iflhs
andrhs
are equal; otherwise returnsfalse
.- __eq__(rhs)
- Parameters:
rhs –
QSizeF
- Return type:
bool
- scale(s, mode)¶
- Parameters:
s –
QSize
mode –
AspectRatioMode
This is an overloaded function.
Scales the size to a rectangle with the given
size
, according to the specifiedmode
.- scale(w, h, mode)
- Parameters:
w – int
h – int
mode –
AspectRatioMode
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Scales the size to a rectangle with the given
width
andheight
, according to the specifiedmode
:If
mode
isIgnoreAspectRatio
, the size is set to (width
,height
).If
mode
isKeepAspectRatio
, the current size is scaled to a rectangle as large as possible inside (width
,height
), preserving the aspect ratio.If
mode
isKeepAspectRatioByExpanding
, the current size is scaled to a rectangle as small as possible outside (width
,height
), preserving the aspect ratio.
Example:
t1 = QSize(10, 12) t1.scale(60, 60, Qt.IgnoreAspectRatio) # t1 is (60, 60) t2 = QSize(10, 12) t2.scale(60, 60, Qt.KeepAspectRatio) # t2 is (50, 60) t3 = QSize(10, 12) t3.scale(60, 60, Qt.KeepAspectRatioByExpanding) # t3 is (60, 72)
See also
- scaled(s, mode)¶
- Parameters:
s –
QSize
mode –
AspectRatioMode
- Return type:
This is an overloaded function.
Return a size scaled to a rectangle with the given size
s
, according to the specifiedmode
.- scaled(w, h, mode)
- Parameters:
w – int
h – int
mode –
AspectRatioMode
- Return type:
Return a size scaled to a rectangle with the given
width
andheight
, according to the specifiedmode
.See also
- setHeight(h)¶
- Parameters:
h – int
Sets the height to the given
height
.See also
rheight()
height()
setWidth()
- setWidth(w)¶
- Parameters:
w – int
Sets the width to the given
width
.See also
rwidth()
width()
setHeight()
Returns this size as a size with floating point accuracy.
See also
- toTuple()¶
- Return type:
object
- transpose()¶
Swaps the width and height values.
See also
Returns a
QSize
with width and height swapped.See also
- width()¶
- Return type:
int
Returns the width.
See also