CopperSpice API  1.7.2
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 w, qreal h)
 
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 c)
 
QSizeF & operator+= (const QSizeF &sizeF)
 
QSizeF & operator-= (const QSizeF &sizeF)
 
QSizeF & operator/= (qreal c)
 
qrealrheight ()
 
qrealrwidth ()
 
void scale (const QSizeF &s, Qt::AspectRatioMode mode)
 
void scale (qreal w, qreal h, Qt::AspectRatioMode mode)
 
QSizeF scaled (const QSizeF &sizeF, Qt::AspectRatioMode mode) const
 
QSizeF scaled (qreal w, qreal h, Qt::AspectRatioMode mode) const
 
void setHeight (qreal h)
 
void setWidth (qreal w)
 
QSize toSize () const
 
void transpose ()
 
QSizeF transposed () const
 
qreal width () const
 

Friends

bool operator!= (const QSizeF &, const QSizeF &)
 
const QSizeF operator* (const QSizeF &, qreal)
 
const QSizeF operator* (qreal, const QSizeF &)
 
const QSizeF operator+ (const QSizeF &, const QSizeF &)
 
const QSizeF operator- (const QSizeF &, const QSizeF &)
 
const QSizeF operator/ (const QSizeF &, qreal)
 
bool operator== (const QSizeF &, const QSizeF &)
 

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() function.

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  w,
qreal  h 
)
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  c)
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 &  sizeF)
inline

Adds the given sizeF 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 &  sizeF)
inline

Subtracts the given sizeF 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  c)
inline

Divides both the width and height by the given delta 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. For example:

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

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

void QSizeF::scale ( qreal  w,
qreal  h,
Qt::AspectRatioMode  mode 
)
inline

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.
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 &  sizeF,
Qt::AspectRatioMode  mode 
) const

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

QSizeF QSizeF::scaled ( qreal  w,
qreal  h,
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  h)
inline

Sets the height to the given height.

See also
height(), rheight(), setWidth()
void QSizeF::setWidth ( qreal  w)
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 &  sizeF,
qreal  delta 
)
friend

Multiplies the given sizeF by the given delta and returns the result.

See also
QSizeF::scale()
const QSizeF operator* ( qreal  delta,
const QSizeF &  sizeF 
)
friend

Multiplies the given sizeF by the given delta 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 &  sizeF,
qreal  delta 
)
friend

Divides the given sizeF by the given delta and returns the result.

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

Writes the given sizeF to the given 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 a size from the given stream into the given sizeF and returns a reference to the stream.

Refer to Serializing Data Types for additional information.