CopperSpice API  1.9.1
QSizeF Class Reference

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

Public Methods

 QSizeF ()
 
 QSizeF (const QSize &size)
 
 QSizeF (qreal width, qreal height)
 
QSizeF boundedTo (const QSizeF &other) const
 
QSizeF expandedTo (const QSizeF &other) const
 
qreal height () const
 
bool isEmpty () const
 
bool isNull () const
 
bool isValid () const
 
QSizeF & operator*= (qreal factor)
 
QSizeF & operator+= (const QSizeF &size)
 
QSizeF & operator-= (const QSizeF &size)
 
QSizeF & operator/= (qreal factor)
 
qrealrheight ()
 
qrealrwidth ()
 
void scale (const QSizeF &size, Qt::AspectRatioMode mode)
 
void scale (qreal width, qreal height, Qt::AspectRatioMode mode)
 
QSizeF scaled (const QSizeF &size, Qt::AspectRatioMode mode) const
 
QSizeF scaled (qreal width, qreal height, Qt::AspectRatioMode mode) const
 
void setHeight (qreal height)
 
void setWidth (qreal width)
 
QSize toSize () const
 
void transpose ()
 
QSizeF transposed () const
 
qreal width () const
 

Friends

bool operator!= (const QSizeF &size1, const QSizeF &size2)
 
const QSizeF operator* (const QSizeF &size, qreal factor)
 
const QSizeF operator* (qreal factor, const QSizeF &size)
 
const QSizeF operator+ (const QSizeF &size1, const QSizeF &size2)
 
const QSizeF operator- (const QSizeF &size1, const QSizeF &size2)
 
const QSizeF operator/ (const QSizeF &size, qreal factor)
 
bool operator== (const QSizeF &size1, const QSizeF &size2)
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QSizeF &sizeF)
 
QDataStreamoperator>> (QDataStream &stream, QSizeF &sizeF)
 

Detailed Description

The QSizeF class defines the size of a two-dimensional object using floating 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() method.

The isValid() function determines if a size is valid. A valid size has both width and height greater than or equal to 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() method 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.

The QSizeF class also provides the toSize() function returning a QSize copy of this size, constructed by rounding the width and height to the nearest integers.

QSizeF objects can be streamed as well as compared.

See also
QSize, QPointF, QRectF

Constructor & Destructor Documentation

QSizeF::QSizeF ( )
inline

Constructs an invalid size.

See also
isValid()
QSizeF::QSizeF ( const QSize size)
inline

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

See also
toSize()
QSizeF::QSizeF ( qreal  width,
qreal  height 
)
inline

Constructs a size with the given width and height.

Method Documentation

QSizeF QSizeF::boundedTo ( const QSizeF &  other) const
inline

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

See also
expandedTo(), scale()
QSizeF QSizeF::expandedTo ( const QSizeF &  other) const
inline

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

See also
boundedTo(), scale()
qreal QSizeF::height ( ) const
inline

Returns the height.

See also
width(), setHeight()
bool QSizeF::isEmpty ( ) const
inline

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

See also
isNull(), isValid()
bool QSizeF::isNull ( ) const
inline

Returns true if both the width and height are +0.0, otherwise returns false.

Note
Since this function treats +0.0 and -0.0 differently, sizes with zero width and height where either or both values have a negative sign are not defined to be null sizes.
See also
isValid(), isEmpty()
bool QSizeF::isValid ( ) const
inline

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

See also
isNull(), isEmpty()
QSizeF & QSizeF::operator*= ( qreal  factor)
inline

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

See also
scale()
QSizeF & QSizeF::operator+= ( const QSizeF &  size)
inline

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

QSizeF s( 3, 7);
QSizeF r(-1, 4);
s += r; // s becomes (2,11)
QSizeF & QSizeF::operator-= ( const QSizeF &  size)
inline

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

QSizeF s( 3, 7);
QSizeF r(-1, 4);
s -= r; // s becomes (4,3)
QSizeF & QSizeF::operator/= ( qreal  factor)
inline

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

See also
scale()
qreal & QSizeF::rheight ( )
inline

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

QSizeF size(100, 10.2);
size.rheight() += 5.5; // size becomes (100,15.7)
See also
rwidth(), setHeight()
qreal & QSizeF::rwidth ( )
inline

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

QSizeF size(100.3, 10);
size.rwidth() += 20.5; // size becomes (120.8,10)
See also
rheight(), setWidth()
void QSizeF::scale ( const QSizeF &  size,
Qt::AspectRatioMode  mode 
)
inline

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

void QSizeF::scale ( qreal  width,
qreal  height,
Qt::AspectRatioMode  mode 
)
inline

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

Qt::IgnoreAspectRatio
size is set to (width, height)
Qt::KeepAspectRatio
size is scaled to a rectangle as large as possible inside (width, height), preserving the aspect ratio.
Qt::KeepAspectRatioByExpanding
size is scaled to a rectangle as small as possible outside (width, height), preserving the aspect ratio.
QSizeF t1(10, 12);
t1.scale(60, 60, Qt::IgnoreAspectRatio); // t1 is (60, 60)
QSizeF t2(10, 12);
t2.scale(60, 60, Qt::KeepAspectRatio); // t2 is (50, 60)
QSizeF t3(10, 12);
t3.scale(60, 60, Qt::KeepAspectRatioByExpanding); // t3 is (60, 72)
See also
setWidth(), setHeight()
QSizeF QSizeF::scaled ( const QSizeF &  size,
Qt::AspectRatioMode  mode 
) const

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

QSizeF QSizeF::scaled ( qreal  width,
qreal  height,
Qt::AspectRatioMode  mode 
) const
inline

Returns a size scaled to a rectangle with the given width and height, according to the specified mode.

void QSizeF::setHeight ( qreal  height)
inline

Sets the height to the given height.

See also
height(), rheight(), setWidth()
void QSizeF::setWidth ( qreal  width)
inline

Sets the width to the given width.

See also
width(), rwidth(), setHeight()
QSize QSizeF::toSize ( ) const
inline

Returns an integer based copy of this size. The coordinates in the returned size will be rounded to the nearest integer.

See also
QSizeF()
void QSizeF::transpose ( )

Swaps the width and height values.

See also
setWidth(), setHeight()
QSizeF QSizeF::transposed ( ) const
inline

Returns the size with width and height values swapped.

See also
transpose()
qreal QSizeF::width ( ) const
inline

Returns the width.

See also
height(), setWidth()

Friends And Related Function Documentation

bool operator!= ( const QSizeF &  size1,
const QSizeF &  size2 
)
friend

Returns true if size1 and size2 are different, otherwise returns false.

const QSizeF operator* ( const QSizeF &  size,
qreal  factor 
)
friend

Multiplies the given size by the given factor and returns the result.

See also
QSizeF::scale()
const QSizeF operator* ( qreal  factor,
const QSizeF &  size 
)
friend

Multiplies the given size by the given factor and returns the result.

const QSizeF operator+ ( const QSizeF &  size1,
const QSizeF &  size2 
)
friend

Returns the sum of size1 and size2, each component is added separately.

const QSizeF operator- ( const QSizeF &  size1,
const QSizeF &  size2 
)
friend

Returns size2 subtracted from size1, each component is subtracted separately.

const QSizeF operator/ ( const QSizeF &  size,
qreal  factor 
)
friend

Divides the given size by the given factor and returns the result.

See also
QSizeF::scale()
QDataStream & operator<< ( QDataStream stream,
const QSizeF &  sizeF 
)
related

Writes sizeF to the stream and returns a reference to the stream.

Refer to Serializing Data Types for additional information.

bool operator== ( const QSizeF &  size1,
const QSizeF &  size2 
)
friend

Returns true if size1 and size2 are equal, otherwise returns false.

QDataStream & operator>> ( QDataStream stream,
QSizeF &  sizeF 
)
related

Reads from the stream into sizeF and returns a reference to the stream.

Refer to Serializing Data Types for additional information.