|  | Home · All Classes · Modules

# QSize Class Reference
[QtCore module]

The QSize class defines the size of a two-dimensional object using integer point precision. More...

### Methods

- __init__ (self)
- __init__ (self, int, int)
- __init__ (self, QSize)
- QSize boundedTo (self, QSize)
- QSize expandedTo (self, QSize)
- int height (self)
- bool isEmpty (self)
- bool isNull (self)
- bool isValid (self)
- scale (self, QSize, Qt.AspectRatioMode)
- scale (self, int, int, Qt.AspectRatioMode)
- setHeight (self, int)
- setWidth (self, int)
- transpose (self)
- int width (self)

### Special Methods

- QSize __add__ (self, QSize)
- int __bool__ (self)
- QSize __div__ (self, float)
- bool __eq__ (self, QSize)
- QSize __iadd__ (self, QSize)
- QSize __idiv__ (self, float)
- QSize __imul__ (self, float)
- QSize __isub__ (self, QSize)
- QSize __mul__ (self, float)
- QSize __mul__ (self, QSize)
- bool __ne__ (self, QSize)
- str __repr__ (self)
- QSize __sub__ (self, QSize)

## Detailed Description

This class can be pickled.

The QSize class defines the size of a two-dimensional object using integer point precision.

A size is specified by a width() and a height(). It can be set in the constructor and changed using the setWidth(), setHeight(), or scale() functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using the rwidth() and rheight() functions. Finally, the width and height can be swapped using the transpose() function.

The isValid() function determines if a size is valid (a valid size has both width and height greater than zero). The isEmpty() function returns true if either of the width and height is less than, or equal to, zero, while the isNull() function returns true 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, the boundedTo() 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.

See also QSizeF, QPoint, and QRect.

## Method Documentation

### QSize.__init__ (self)

Constructs a size with an invalid width and height (i.e., isValid() returns false).

See also isValid().

### QSize.__init__ (self, int, int)

Constructs a size with the given width and height.

See also setWidth() and setHeight().

### QSize.__init__ (self, QSize)

### QSize QSize.boundedTo (self, QSize)

Returns a size holding the minimum width and height of this size and the given otherSize.

See also expandedTo() and scale().

### QSize QSize.expandedTo (self, QSize)

Returns a size holding the maximum width and height of this size and the given otherSize.

See also boundedTo() and scale().

### int QSize.height (self)

Returns the height.

See also width() and setHeight().

### bool QSize.isEmpty (self)

Returns true if either of the width and height is less than or equal to 0; otherwise returns false.

See also isNull() and isValid().

### bool QSize.isNull (self)

Returns true if both the width and height is 0; otherwise returns false.

See also isValid() and isEmpty().

### bool QSize.isValid (self)

Returns true if both the width and height is equal to or greater than 0; otherwise returns false.

See also isNull() and isEmpty().

### QSize.scale (self, QSize, Qt.AspectRatioMode)

Scales the size to a rectangle with the given width and height, according to the specified mode:

- If mode is Qt.IgnoreAspectRatio, the size is set to (width, height).
- If mode is Qt.KeepAspectRatio, the current size is scaled to a rectangle as large as possible inside (width, height), preserving the aspect ratio.
- If mode is Qt.KeepAspectRatioByExpanding, the current size is scaled to a rectangle as small as possible outside (width, height), preserving the aspect ratio.

Example:

     QSize t1(10, 12);
     t1.scale(60, 60, Qt.IgnoreAspectRatio);
     // t1 is (60, 60)

     QSize t2(10, 12);
     t2.scale(60, 60, Qt.KeepAspectRatio);
     // t2 is (50, 60)

     QSize t3(10, 12);
     t3.scale(60, 60, Qt.KeepAspectRatioByExpanding);
     // t3 is (60, 72)

See also setWidth() and setHeight().

### QSize.scale (self, int, int, Qt.AspectRatioMode)

This is an overloaded function.

Scales the size to a rectangle with the given size, according to the specified mode.

### QSize.setHeight (self, int)

Sets the height to the given height.

See also rheight(), height(), and setWidth().

### QSize.setWidth (self, int)

Sets the width to the given width.

See also rwidth(), width(), and setHeight().

### QSize.transpose (self)

Swaps the width and height values.

See also setWidth() and setHeight().

### int QSize.width (self)

Returns the width.

See also height() and setWidth().

### QSize QSize.__add__ (self, QSize)

### int QSize.__bool__ (self)

### QSize QSize.__div__ (self, float)

### bool QSize.__eq__ (self, QSize)

### QSize QSize.__iadd__ (self, QSize)

### QSize QSize.__idiv__ (self, float)

### QSize QSize.__imul__ (self, float)

### QSize QSize.__isub__ (self, QSize)

### QSize QSize.__mul__ (self, float)

### QSize QSize.__mul__ (self, QSize)

### bool QSize.__ne__ (self, QSize)

### str QSize.__repr__ (self)

### QSize QSize.__sub__ (self, QSize)