Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QSizeF Class Reference

\inmodule QtCore More...

#include <qsize.h>

+ Inheritance diagram for QSizeF:
+ Collaboration diagram for QSizeF:

Public Member Functions

constexpr QSizeF () noexcept
 Constructs an invalid size.
 
constexpr QSizeF (const QSize &sz) noexcept
 Constructs a size with floating point accuracy from the given size.
 
constexpr QSizeF (qreal w, qreal h) noexcept
 Constructs a size with the given finite width and height.
 
bool isNull () const noexcept
 Returns true if both the width and height are 0.0 (ignoring the sign); otherwise returns false.
 
constexpr bool isEmpty () const noexcept
 Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
 
constexpr bool isValid () const noexcept
 Returns true if both the width and height are equal to or greater than 0; otherwise returns false.
 
constexpr qreal width () const noexcept
 Returns the width.
 
constexpr qreal height () const noexcept
 Returns the height.
 
constexpr void setWidth (qreal w) noexcept
 Sets the width to the given finite width.
 
constexpr void setHeight (qreal h) noexcept
 Sets the height to the given finite height.
 
void transpose () noexcept
 Swaps the width and height values.
 
constexpr QSizeF transposed () const noexcept
 
void scale (qreal w, qreal h, Qt::AspectRatioMode mode) noexcept
 Scales the size to a rectangle with the given width and height, according to the specified mode.
 
void scale (const QSizeF &s, Qt::AspectRatioMode mode) noexcept
 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.
 
QSizeF scaled (qreal w, qreal h, Qt::AspectRatioMode mode) const noexcept
 
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.
 
constexpr QSizeF expandedTo (const QSizeF &) const noexcept
 Returns a size holding the maximum width and height of this size and the given otherSize.
 
constexpr QSizeF boundedTo (const QSizeF &) const noexcept
 Returns a size holding the minimum width and height of this size and the given otherSize.
 
constexpr QSizeF grownBy (QMarginsF m) const noexcept
 
constexpr QSizeF shrunkBy (QMarginsF m) const noexcept
 
constexpr qrealrwidth () noexcept
 Returns a reference to the width.
 
constexpr qrealrheight () noexcept
 Returns a reference to the height.
 
constexpr QSizeFoperator+= (const QSizeF &) noexcept
 Adds the given size to this size and returns a reference to this size.
 
constexpr QSizeFoperator-= (const QSizeF &) noexcept
 Subtracts the given size from this size and returns a reference to this size.
 
constexpr QSizeFoperator*= (qreal c) noexcept
 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.
 
QSizeFoperator/= (qreal c)
 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.
 
constexpr QSize toSize () const noexcept
 Returns an integer based copy of this size.
 

Friends

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE friend constexpr bool qFuzzyCompare (const QSizeF &s1, const QSizeF &s2) noexcept
 
QT_WARNING_POP friend constexpr bool qFuzzyIsNull (const QSizeF &size) noexcept
 
constexpr bool comparesEqual (const QSizeF &lhs, const QSizeF &rhs) noexcept
 
constexpr bool comparesEqual (const QSizeF &lhs, const QSize &rhs) noexcept
 
constexpr QSizeF operator+ (const QSizeF &s1, const QSizeF &s2) noexcept
 Returns the sum of s1 and s2; each component is added separately.
 
constexpr QSizeF operator- (const QSizeF &s1, const QSizeF &s2) noexcept
 Returns s2 subtracted from s1; each component is subtracted separately.
 
constexpr QSizeF operator* (const QSizeF &s, qreal c) noexcept
 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.
 
constexpr QSizeF operator* (qreal c, const QSizeF &s) noexcept
 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.
 
QSizeF operator/ (const QSizeF &s, qreal c)
 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.
 
template<std::size_t I, typename S , std::enable_if_t<(I< 2), bool > = true, std::enable_if_t< std::is_same_v< q20::remove_cvref_t< S >, QSizeF >, bool > = true>
constexpr decltype(auto) get (S &&s) noexcept
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &stream, const QSizeF &size)
 Writes the given size to the given stream and returns a reference to the stream.
 
QDataStreamoperator>> (QDataStream &stream, QSizeF &size)
 Reads a size from the given stream into the given size and returns a reference to the stream.
 

Detailed Description

\inmodule QtCore

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() 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 207 of file qsize.h.

Constructor & Destructor Documentation

◆ QSizeF() [1/3]

QSizeF::QSizeF ( )
inlineconstexprnoexcept

Constructs an invalid size.

See also
isValid()

Definition at line 317 of file qsize.h.

◆ QSizeF() [2/3]

QSizeF::QSizeF ( const QSize & size)
inlineconstexprnoexcept

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

See also
toSize(), QSize::toSizeF()

Definition at line 319 of file qsize.h.

◆ QSizeF() [3/3]

QSizeF::QSizeF ( qreal w,
qreal h )
inlineconstexprnoexcept

Constructs a size with the given finite width and height.

Definition at line 321 of file qsize.h.

Member Function Documentation

◆ boundedTo()

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

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

See also
expandedTo(), scale()

Definition at line 396 of file qsize.h.

◆ expandedTo()

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

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

See also
boundedTo(), scale()

Definition at line 391 of file qsize.h.

◆ grownBy()

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

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

See also
shrunkBy()

Definition at line 233 of file qsize.h.

◆ height()

qreal QSizeF::height ( ) const
inlineconstexprnoexcept

Returns the height.

See also
width(), setHeight()

Definition at line 335 of file qsize.h.

◆ isEmpty()

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 326 of file qsize.h.

◆ 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 323 of file qsize.h.

◆ isValid()

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 329 of file qsize.h.

◆ operator*=()

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 376 of file qsize.h.

◆ operator+=()

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

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

For example:

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

Definition at line 362 of file qsize.h.

◆ operator-=()

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

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

For example:

QSizeF s( 3, 7);
QSizeF r(-1, 4);
s -= r;
// s becomes (4,3)
@ KeepAspectRatioByExpanding
@ IgnoreAspectRatio
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
#define t3
#define t2
#define t1

Definition at line 369 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 383 of file qsize.h.

◆ rheight()

qreal & QSizeF::rheight ( )
inlineconstexprnoexcept

Returns a reference to the height.

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

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

Definition at line 359 of file qsize.h.

◆ rwidth()

qreal & QSizeF::rwidth ( )
inlineconstexprnoexcept

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

Definition at line 356 of file qsize.h.

◆ scale() [1/2]

void QSizeF::scale ( const QSizeF & s,
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 350 of file qsize.h.

◆ 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:

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 is (60, 72)
See also
setWidth(), setHeight(), scaled()

Definition at line 347 of file qsize.h.

◆ scaled() [1/2]

QSizeF QSizeF::scaled ( const QSizeF & s,
Qt::AspectRatioMode mode ) const
nodiscardnoexcept

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 640 of file qsize.cpp.

◆ scaled() [2/2]

QSizeF QSizeF::scaled ( qreal width,
qreal height,
Qt::AspectRatioMode mode ) const
inlinenodiscardnoexcept
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 353 of file qsize.h.

◆ setHeight()

void QSizeF::setHeight ( qreal height)
inlineconstexprnoexcept

Sets the height to the given finite height.

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

Definition at line 341 of file qsize.h.

◆ setWidth()

void QSizeF::setWidth ( qreal width)
inlineconstexprnoexcept

Sets the width to the given finite width.

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

Definition at line 338 of file qsize.h.

◆ shrunkBy()

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

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

See also
grownBy()

Definition at line 235 of file qsize.h.

◆ toSize()

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(), QSize::toSizeF()

Definition at line 401 of file qsize.h.

◆ transpose()

void QSizeF::transpose ( )
noexcept

Swaps the width and height values.

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

Definition at line 581 of file qsize.cpp.

◆ transposed()

QSizeF QSizeF::transposed ( ) const
inlinenodiscardconstexprnoexcept
Since
5.0

Returns the size with width and height values swapped.

See also
transpose()

Definition at line 344 of file qsize.h.

◆ width()

qreal QSizeF::width ( ) const
inlineconstexprnoexcept

Returns the width.

See also
height(), setWidth()

Definition at line 332 of file qsize.h.

Friends And Related Symbol Documentation

◆ comparesEqual [1/2]

bool comparesEqual ( const QSizeF & lhs,
const QSize & rhs )
friend

Definition at line 262 of file qsize.h.

◆ comparesEqual [2/2]

bool comparesEqual ( const QSizeF & lhs,
const QSizeF & rhs )
friend

Definition at line 259 of file qsize.h.

◆ get

template<std::size_t I, typename S , std::enable_if_t<(I< 2), bool > = true, std::enable_if_t< std::is_same_v< q20::remove_cvref_t< S >, QSizeF >, bool > = true>
decltype(auto) get ( S && s)
friend

Definition at line 292 of file qsize.h.

◆ operator* [1/2]

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 269 of file qsize.h.

◆ operator* [2/2]

QSizeF operator* ( qreal c,
const QSizeF & s )
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 271 of file qsize.h.

◆ operator+

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

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

Definition at line 265 of file qsize.h.

◆ operator-

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

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

Definition at line 267 of file qsize.h.

◆ operator/

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 273 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}

◆ 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}

◆ qFuzzyCompare

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE friend constexpr bool qFuzzyCompare ( const QSizeF & lhs,
const QSizeF & rhs )
friend
Since
6.8

Returns true if the size lhs is approximately equal to the size rhs; otherwise returns false.

The sizes are considered approximately equal if their width and height are approximately equal.

Definition at line 249 of file qsize.h.

◆ qFuzzyIsNull

QT_WARNING_POP friend constexpr bool qFuzzyIsNull ( const QSizeF & size)
friend
Since
6.8

Returns true if both width and height of the size size are approximately equal to zero.

Definition at line 257 of file qsize.h.


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