Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QSizeF Class Reference

The QSizeF class defines the size of a two-dimensional object using floating point values for accuracy. More...

    #include <QSizeF>

- List of all members, including inherited members

### Public Functions

- QSizeF ()
- QSizeF ( const QSize & size )
- QSizeF ( float width, float height )
- QSizeF boundedTo ( const QSizeF & otherSize ) const
- QSizeF expandedTo ( const QSizeF & otherSize ) const
- float height () const
- bool isEmpty () const
- bool isNull () const
- bool isValid () const
- float & rheight ()
- float & rwidth ()
- void scale ( float w, float h, Qt::AspectRatioMode mode )
- void scale ( const QSizeF & s, Qt::AspectRatioMode mode )
- void setHeight ( float height )
- void setWidth ( float width )
- QSize toSize () const
- void transpose ()
- float width () const
- QSizeF & operator*= ( int c )
- QSizeF & operator*= ( float c )
- QSizeF & operator+= ( const QSizeF & s )
- QSizeF & operator-= ( const QSizeF & s )
- QSizeF & operator/= ( int c )
- QSizeF & operator/= ( float c )

### Related Non-Members

- bool operator!= ( const QSizeF & s1, const QSizeF & s2 )
- const QSizeF operator* ( const QSizeF & s, int c )
- const QSizeF operator* ( int c, const QSizeF & s )
- const QSizeF operator* ( const QSizeF & s, float c )
- const QSizeF operator* ( float c, const QSizeF & s )
- const QSizeF operator+ ( const QSizeF & s1, const QSizeF & s2 )
- const QSizeF operator- ( const QSizeF & s1, const QSizeF & s2 )
- const QSizeF operator/ ( const QSizeF & s, int c )
- const QSizeF operator/ ( const QSizeF & s, float c )
- QDataStream & operator<< ( QDataStream & s, const QSizeF & sz )
- bool operator== ( const QSizeF & s1, const QSizeF & s2 )
- QDataStream & operator>> ( QDataStream & s, QSizeF & sz )

## Detailed Description

The QSizeF class defines the size of a two-dimensional object using floating point values for accuracy.

A size is specified by a width and a height.

The coordinate type is float.

The size can be set in the constructor and changed with setWidth(), setHeight(), or scale(), or using operator+=(), operator-=(), operator*=() and operator/=(), etc. You can swap the width and height with transpose(). You can get a size which holds the maximum height and width of two sizes using expandedTo(), and the minimum height and width of two sizes using boundedTo().

See also QSize, QPointF, and QRectF.

## Member Function Documentation

### QSizeF::QSizeF ()

Constructs a size with invalid width and height.

See also isValid(), setWidth(), and setHeight().

### QSizeF::QSizeF ( const QSize & size )

Constructs a size with floating point accuracy from the given size.

### QSizeF::QSizeF ( float width, float height )

Constructs a size with width width and height height.

### QSizeF QSizeF::boundedTo ( const QSizeF & otherSize ) const

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

See also expandedTo(), scale(), setWidth(), and setHeight().

### QSizeF QSizeF::expandedTo ( const QSizeF & otherSize ) const

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

See also boundedTo(), scale(), setWidth(), and setHeight().

### float QSizeF::height () const

Returns the height.

See also width().

### bool QSizeF::isEmpty () const

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

See also isNull(), isValid(), width(), and height().

### bool QSizeF::isNull () const

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

See also isValid(), isEmpty(), width(), and height().

### bool QSizeF::isValid () const

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

See also isNull(), isEmpty(), width(), and height().

### float & QSizeF::rheight ()

Returns a reference to the height.

Using a reference makes it possible to directly manipulate the height.

Example:

        QSizeF s(100, 10);
        s.rheight() += 5;                // s becomes (100,15)

See also rwidth() and setHeight().

### float & QSizeF::rwidth ()

Returns a reference to the width.

Using a reference makes it possible to directly manipulate the width.

Example:

        QSizeF s(100, 10);
        s.rwidth() += 20;                // s becomes (120,10)

See also rheight() and setWidth().

### void QSizeF::scale ( float w, float h, Qt::AspectRatioMode mode )

Scales the size to a rectangle of width w and height h according to the Qt::AspectRatioMode mode.

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

Example:

        QSizeF t1(10, 12);
        t1.scale(60, 60, QSizeF::IgnoreAspectRatio);
        // t1 is (60, 60)

        QSizeF t2(10, 12);
        t2.scale(60, 60, QSizeF::KeepAspectRatio);
        // t2 is (50, 60)

        QSizeF t3(10, 12);
        t3.scale(60, 60, QSizeF::KeepAspectRatioByExpanding);
        // t3 is (60, 72)

See also boundedTo(), expandedTo(), setWidth(), and setHeight().

### void QSizeF::scale ( const QSizeF & s, Qt::AspectRatioMode mode )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Equivalent to scale(s.width(), s.height(), mode).

### void QSizeF::setHeight ( float height )

Sets the height to height.

See also height(), setWidth(), expandedTo(), boundedTo(), scale(), and transpose().

### void QSizeF::setWidth ( float width )

Sets the width to width.

See also width(), setHeight(), expandedTo(), boundedTo(), scale(), and transpose().

### QSize QSizeF::toSize () const

Returns a size with integer precision. Note that the coordinates in the returned size are less precise than those in the floating point size.

### void QSizeF::transpose ()

Swaps the width and height values.

See also expandedTo(), boundedTo(), setWidth(), and setHeight().

### float QSizeF::width () const

Returns the width.

See also height().

### QSizeF & QSizeF::operator*= ( int c )

Multiplies both the width and height by c and returns a reference to the size.

See also scale().

### QSizeF & QSizeF::operator*= ( float c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Multiplies both the width and height by c and returns a reference to the size.

Note that the result is truncated.

### QSizeF & QSizeF::operator+= ( const QSizeF & s )

Adds s to the size and returns a reference to this size.

Example:

        QSizeF s( 3, 7);
        QSizeF r(-1, 4);
        s += r;                        // s becomes (2,11)

### QSizeF & QSizeF::operator-= ( const QSizeF & s )

Subtracts s from the size and returns a reference to this size.

Example:

        QSizeF s( 3, 7);
        QSizeF r(-1, 4);
        s -= r;                        // s becomes (4,3)

### QSizeF & QSizeF::operator/= ( int c )

Divides both the width and height by c and returns a reference to the size.

See also scale().

### QSizeF & QSizeF::operator/= ( float c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Divides both the width and height by c and returns a reference to the size.

Note that the result is truncated.

See also scale().

## Related Non-Members

### bool operator!= ( const QSizeF & s1, const QSizeF & s2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if s1 and s2 are different; otherwise returns false.

### const QSizeF operator* ( const QSizeF & s, int c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Multiplies s by c and returns the result.

See also scale().

### const QSizeF operator* ( int c, const QSizeF & s )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Multiplies s by c and returns the result.

See also scale().

### const QSizeF operator* ( const QSizeF & s, float c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Multiplies s by c and returns the result.

See also scale().

### const QSizeF operator* ( float c, const QSizeF & s )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Multiplies s by c and returns the result.

See also scale().

### const QSizeF operator+ ( const QSizeF & s1, const QSizeF & s2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the sum of s1 and s2; each component is added separately.

See also scale().

### const QSizeF operator- ( const QSizeF & s1, const QSizeF & s2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns s2 subtracted from s1; each component is subtracted separately.

See also scale().

### const QSizeF operator/ ( const QSizeF & s, int c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Divides s by c and returns the result.

See also scale().

### const QSizeF operator/ ( const QSizeF & s, float c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Divides s by c and returns the result.

Note that the result is truncated.

See also scale().

### QDataStream & operator<< ( QDataStream & s, const QSizeF & sz )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Writes the size sz to the stream s and returns a reference to the stream.

See also Format of the QDataStream operators.

### bool operator== ( const QSizeF & s1, const QSizeF & s2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if s1 and s2 are equal; otherwise returns false.

### QDataStream & operator>> ( QDataStream & s, QSizeF & sz )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reads the size from the stream s into size sz and returns a reference to the stream.

See also Format of the QDataStream operators.