QtBase  v6.3.1
Public Member Functions | Friends | Related Functions | List of all members
QSizeF Class Reference

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

#include <qsize.h>

Public Member Functions

constexpr QSizeF () noexcept
 
constexpr QSizeF (const QSize &sz) noexcept
 
constexpr QSizeF (qreal w, qreal h) noexcept
 
bool isNull () const noexcept
 
constexpr bool isEmpty () const noexcept
 
constexpr bool isValid () const noexcept
 
constexpr qreal width () const noexcept
 
constexpr qreal height () const noexcept
 
constexpr void setWidth (qreal w) noexcept
 
constexpr void setHeight (qreal h) noexcept
 
void transpose () noexcept
 
constexpr QSizeF transposed () const noexcept
 
void scale (qreal w, qreal h, Qt::AspectRatioMode mode) noexcept
 
void scale (const QSizeF &s, Qt::AspectRatioMode mode) noexcept
 
QSizeF scaled (qreal w, qreal h, Qt::AspectRatioMode mode) const noexcept
 
QSizeF scaled (const QSizeF &s, Qt::AspectRatioMode mode) const noexcept
 
constexpr QSizeF expandedTo (const QSizeF &) const noexcept
 
constexpr QSizeF boundedTo (const QSizeF &) const noexcept
 
constexpr QSizeF grownBy (QMarginsF m) const noexcept
 
constexpr QSizeF shrunkBy (QMarginsF m) const noexcept
 
constexpr qrealrwidth () noexcept
 
constexpr qrealrheight () noexcept
 
constexpr QSizeFoperator+= (const QSizeF &) noexcept
 
constexpr QSizeFoperator-= (const QSizeF &) noexcept
 
constexpr QSizeFoperator*= (qreal c) noexcept
 
QSizeFoperator/= (qreal c)
 
constexpr QSize toSize () const noexcept
 

Friends

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr friend bool operator== (const QSizeF &s1, const QSizeF &s2)
 
QT_WARNING_POP constexpr friend bool operator!= (const QSizeF &s1, const QSizeF &s2)
 
constexpr friend QSizeF operator+ (const QSizeF &s1, const QSizeF &s2) noexcept
 
constexpr friend QSizeF operator- (const QSizeF &s1, const QSizeF &s2) noexcept
 
constexpr friend QSizeF operator* (const QSizeF &s, qreal c) noexcept
 
constexpr friend QSizeF operator* (qreal c, const QSizeF &s) noexcept
 
QSizeF operator/ (const QSizeF &s, qreal c)
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

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

\inmodule QtCore

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

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

Definition at line 234 of file qsize.h.

Constructor & Destructor Documentation

◆ QSizeF() [1/3]

constexpr QSizeF::QSizeF ( )
inlineconstexprnoexcept

Constructs an invalid size.

See also
isValid()

Definition at line 334 of file qsize.h.

◆ QSizeF() [2/3]

constexpr QSizeF::QSizeF ( const QSize size)
inlineconstexprnoexcept

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

See also
toSize()

Definition at line 336 of file qsize.h.

◆ QSizeF() [3/3]

constexpr QSizeF::QSizeF ( qreal  width,
qreal  height 
)
inlineconstexprnoexcept

Constructs a size with the given finite width and height.

Definition at line 338 of file qsize.h.

Member Function Documentation

◆ boundedTo()

constexpr QSizeF QSizeF::boundedTo ( const QSizeF otherSize) const
inlineconstexprnoexcept

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

See also
expandedTo(), scale()

Definition at line 413 of file qsize.h.

Here is the caller graph for this function:

◆ expandedTo()

constexpr QSizeF QSizeF::expandedTo ( const QSizeF otherSize) const
inlineconstexprnoexcept

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

See also
boundedTo(), scale()

Definition at line 408 of file qsize.h.

◆ grownBy()

QSizeF QSizeF::grownBy ( QMarginsF  margins) const
inlineconstexprnoexcept
Since
5.14

Returns the size that results from growing this size by margins.

See also
shrunkBy()

Definition at line 260 of file qsize.h.

◆ height()

constexpr qreal QSizeF::height ( ) const
inlineconstexprnoexcept

Returns the height.

See also
width(), setHeight()

Definition at line 352 of file qsize.h.

Here is the caller graph for this function:

◆ isEmpty()

constexpr bool QSizeF::isEmpty ( ) const
inlineconstexprnoexcept

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

See also
isNull(), isValid()

Definition at line 343 of file qsize.h.

Here is the caller graph for this function:

◆ isNull()

bool QSizeF::isNull ( ) const
inlinenoexcept

Returns true if both the width and height are 0.0 (ignoring the sign); otherwise returns false.

See also
isValid(), isEmpty()

Definition at line 340 of file qsize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValid()

constexpr bool QSizeF::isValid ( ) const
inlineconstexprnoexcept

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

See also
isNull(), isEmpty()

Definition at line 346 of file qsize.h.

Here is the caller graph for this function:

◆ operator*=()

constexpr QSizeF & QSizeF::operator*= ( qreal  factor)
inlineconstexprnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

See also
scale()

Definition at line 393 of file qsize.h.

◆ operator+=()

constexpr QSizeF & QSizeF::operator+= ( const QSizeF size)
inlineconstexprnoexcept

Adds the given size to this size and returns a reference to this size. For example:

Definition at line 379 of file qsize.h.

◆ operator-=()

constexpr QSizeF & QSizeF::operator-= ( const QSizeF size)
inlineconstexprnoexcept

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

Definition at line 386 of file qsize.h.

◆ operator/=()

QSizeF & QSizeF::operator/= ( qreal  divisor)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Divides both the width and height by the given divisor and returns a reference to the size. The divisor must not be either zero or NaN.

See also
scale()

Definition at line 400 of file qsize.h.

Here is the call graph for this function:

◆ rheight()

constexpr qreal & QSizeF::rheight ( )
inlineconstexprnoexcept

Returns a reference to the height.

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

See also
rwidth(), setHeight()

Definition at line 376 of file qsize.h.

◆ rwidth()

constexpr qreal & QSizeF::rwidth ( )
inlineconstexprnoexcept

Returns a reference to the width.

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

See also
rheight(), setWidth()

Definition at line 373 of file qsize.h.

◆ scale() [1/2]

void QSizeF::scale ( const QSizeF size,
Qt::AspectRatioMode  mode 
)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 367 of file qsize.h.

Here is the call graph for this function:

◆ scale() [2/2]

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

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

\list

  • 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. \endlist

Example:

See also
setWidth(), setHeight(), scaled()

Definition at line 364 of file qsize.h.

◆ scaled() [1/2]

QSizeF QSizeF::scaled ( const QSizeF s,
Qt::AspectRatioMode  mode 
) const
noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.0

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

Definition at line 667 of file qsize.cpp.

Here is the call graph for this function:

◆ scaled() [2/2]

QSizeF QSizeF::scaled ( qreal  width,
qreal  height,
Qt::AspectRatioMode  mode 
) const
inlinenoexcept
Since
5.0

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

See also
scale()

Definition at line 370 of file qsize.h.

Here is the call graph for this function:

◆ setHeight()

constexpr void QSizeF::setHeight ( qreal  height)
inlineconstexprnoexcept

Sets the height to the given finite height.

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

Definition at line 358 of file qsize.h.

Here is the caller graph for this function:

◆ setWidth()

constexpr void QSizeF::setWidth ( qreal  width)
inlineconstexprnoexcept

Sets the width to the given finite width.

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

Definition at line 355 of file qsize.h.

Here is the caller graph for this function:

◆ shrunkBy()

QSizeF QSizeF::shrunkBy ( QMarginsF  margins) const
inlineconstexprnoexcept
Since
5.14

Returns the size that results from shrinking this size by margins.

See also
grownBy()

Definition at line 262 of file qsize.h.

◆ toSize()

constexpr QSize QSizeF::toSize ( ) const
inlineconstexprnoexcept

Returns an integer based copy of this size.

Note that the coordinates in the returned size will be rounded to the nearest integer.

See also
QSizeF()

Definition at line 418 of file qsize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transpose()

void QSizeF::transpose ( )
noexcept

Swaps the width and height values.

See also
setWidth(), setHeight(), transposed()

Definition at line 608 of file qsize.cpp.

Here is the call graph for this function:

◆ transposed()

constexpr QSizeF QSizeF::transposed ( ) const
inlineconstexprnoexcept
Since
5.0

Returns the size with width and height values swapped.

See also
transpose()

Definition at line 361 of file qsize.h.

Here is the caller graph for this function:

◆ width()

constexpr qreal QSizeF::width ( ) const
inlineconstexprnoexcept

Returns the width.

See also
height(), setWidth()

Definition at line 349 of file qsize.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool QSizeF::operator!= ( const QSizeF s1,
const QSizeF s2 
)
friend

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

Warning
This function does not check for strict inequality; instead, it uses a fuzzy comparison to compare the sizes' extents.

Definition at line 281 of file qsize.h.

◆ operator* [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

See also
QSizeF::scale()

Definition at line 287 of file qsize.h.

◆ operator* [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 289 of file qsize.h.

◆ operator+

QSizeF QSizeF::operator+ ( const QSizeF s1,
const QSizeF s2 
)
friend

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

Definition at line 283 of file qsize.h.

◆ operator-

QSizeF QSizeF::operator- ( const QSizeF s1,
const QSizeF s2 
)
friend

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

Definition at line 285 of file qsize.h.

◆ operator/

QSizeF QSizeF::operator/ ( const QSizeF size,
qreal  divisor 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Divides the given size by the given divisor and returns the result. The divisor must not be either zero or NaN.

See also
QSizeF::scale()

Definition at line 291 of file qsize.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QSizeF size 
)
related

Writes the given size to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 854 of file qsize.cpp.

Here is the call graph for this function:

◆ operator==

bool QSizeF::operator== ( const QSizeF s1,
const QSizeF s2 
)
friend

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

Warning
This function does not check for strict equality; instead, it uses a fuzzy comparison to compare the sizes' extents.
See also
qFuzzyCompare

Definition at line 275 of file qsize.h.

◆ operator>>()

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

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

See also
{Serializing Qt Data Types}

Definition at line 870 of file qsize.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: