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

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

#include <qsize.h>

Public Member Functions

constexpr QSize () noexcept
 
constexpr QSize (int w, int h) noexcept
 
constexpr bool isNull () const noexcept
 
constexpr bool isEmpty () const noexcept
 
constexpr bool isValid () const noexcept
 
constexpr int width () const noexcept
 
constexpr int height () const noexcept
 
constexpr void setWidth (int w) noexcept
 
constexpr void setHeight (int h) noexcept
 
void transpose () noexcept
 
constexpr QSize transposed () const noexcept
 
void scale (int w, int h, Qt::AspectRatioMode mode) noexcept
 
void scale (const QSize &s, Qt::AspectRatioMode mode) noexcept
 
QSize scaled (int w, int h, Qt::AspectRatioMode mode) const noexcept
 
QSize scaled (const QSize &s, Qt::AspectRatioMode mode) const noexcept
 
constexpr QSize expandedTo (const QSize &) const noexcept
 
constexpr QSize boundedTo (const QSize &) const noexcept
 
constexpr QSize grownBy (QMargins m) const noexcept
 
constexpr QSize shrunkBy (QMargins m) const noexcept
 
constexpr int & rwidth () noexcept
 
constexpr int & rheight () noexcept
 
constexpr QSizeoperator+= (const QSize &) noexcept
 
constexpr QSizeoperator-= (const QSize &) noexcept
 
constexpr QSizeoperator*= (qreal c) noexcept
 
QSizeoperator/= (qreal c)
 

Friends

constexpr friend bool operator== (const QSize &s1, const QSize &s2) noexcept
 
constexpr friend bool operator!= (const QSize &s1, const QSize &s2) noexcept
 
constexpr friend QSize operator+ (const QSize &s1, const QSize &s2) noexcept
 
constexpr friend QSize operator- (const QSize &s1, const QSize &s2) noexcept
 
constexpr friend QSize operator* (const QSize &s, qreal c) noexcept
 
constexpr friend QSize operator* (qreal c, const QSize &s) noexcept
 
QSize operator/ (const QSize &s, qreal c)
 
constexpr friend size_t qHash (const QSize &, size_t) noexcept
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

The QSize class defines the size of a two-dimensional object using integer 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.

QSize objects can be streamed as well as compared.

See also
QSizeF, QPoint, QRect

Definition at line 54 of file qsize.h.

Constructor & Destructor Documentation

◆ QSize() [1/2]

constexpr QSize::QSize ( )
inlineconstexprnoexcept

Constructs a size with an invalid width and height (i.e., isValid() returns false).

See also
isValid()

Definition at line 144 of file qsize.h.

◆ QSize() [2/2]

constexpr QSize::QSize ( int  width,
int  height 
)
inlineconstexprnoexcept

Constructs a size with the given width and height.

See also
setWidth(), setHeight()

Definition at line 146 of file qsize.h.

Member Function Documentation

◆ boundedTo()

constexpr QSize QSize::boundedTo ( const QSize 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 224 of file qsize.h.

Here is the caller graph for this function:

◆ expandedTo()

constexpr QSize QSize::expandedTo ( const QSize 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 219 of file qsize.h.

Here is the caller graph for this function:

◆ grownBy()

QSize QSize::grownBy ( QMargins  m) const
inlineconstexprnoexcept

Definition at line 79 of file qsize.h.

Here is the caller graph for this function:

◆ height()

constexpr int QSize::height ( ) const
inlineconstexprnoexcept

Returns the height.

See also
width(), setHeight()

Definition at line 160 of file qsize.h.

Here is the caller graph for this function:

◆ isEmpty()

constexpr bool QSize::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 151 of file qsize.h.

Here is the caller graph for this function:

◆ isNull()

constexpr bool QSize::isNull ( ) const
inlineconstexprnoexcept

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

See also
isValid(), isEmpty()

Definition at line 148 of file qsize.h.

Here is the caller graph for this function:

◆ isValid()

constexpr bool QSize::isValid ( ) const
inlineconstexprnoexcept

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

See also
isNull(), isEmpty()

Definition at line 154 of file qsize.h.

Here is the caller graph for this function:

◆ operator*=()

constexpr QSize & QSize::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 factor, and returns a reference to the size.

Note that the result is rounded to the nearest integer.

See also
scale()

Definition at line 201 of file qsize.h.

Here is the call graph for this function:

◆ operator+=()

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

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

Definition at line 187 of file qsize.h.

◆ operator-=()

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

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

Definition at line 194 of file qsize.h.

◆ operator/=()

QSize & QSize::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.

Note that the result is rounded to the nearest integer.

See also
QSize::scale()

Definition at line 211 of file qsize.h.

Here is the call graph for this function:

◆ rheight()

constexpr int & QSize::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 184 of file qsize.h.

Here is the caller graph for this function:

◆ rwidth()

constexpr int & QSize::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 181 of file qsize.h.

Here is the caller graph for this function:

◆ scale() [1/2]

void QSize::scale ( const QSize 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 175 of file qsize.h.

Here is the call graph for this function:

◆ scale() [2/2]

void QSize::scale ( int  width,
int  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 172 of file qsize.h.

Here is the caller graph for this function:

◆ scaled() [1/2]

QSize QSize::scaled ( const QSize 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

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

Definition at line 225 of file qsize.cpp.

◆ scaled() [2/2]

QSize QSize::scaled ( int  width,
int  height,
Qt::AspectRatioMode  mode 
) const
inlinenoexcept
Since
5.0

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

See also
scale()

Definition at line 178 of file qsize.h.

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

◆ setHeight()

constexpr void QSize::setHeight ( int  height)
inlineconstexprnoexcept

Sets the height to the given height.

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

Definition at line 166 of file qsize.h.

Here is the caller graph for this function:

◆ setWidth()

constexpr void QSize::setWidth ( int  width)
inlineconstexprnoexcept

Sets the width to the given width.

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

Definition at line 163 of file qsize.h.

Here is the caller graph for this function:

◆ shrunkBy()

QSize QSize::shrunkBy ( QMargins  m) const
inlineconstexprnoexcept

Definition at line 81 of file qsize.h.

◆ transpose()

void QSize::transpose ( )
noexcept

Swaps the width and height values.

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

Definition at line 166 of file qsize.cpp.

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

◆ transposed()

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

Returns a QSize with width and height swapped.

See also
transpose()

Definition at line 169 of file qsize.h.

Here is the caller graph for this function:

◆ width()

constexpr int QSize::width ( ) const
inlineconstexprnoexcept

Returns the width.

See also
height(), setWidth()

Definition at line 157 of file qsize.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

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

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

Definition at line 94 of file qsize.h.

◆ operator* [1/2]

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

Multiplies the given size by the given factor, and returns the result rounded to the nearest integer.

See also
QSize::scale()

Definition at line 100 of file qsize.h.

◆ operator* [2/2]

QSize QSize::operator* ( qreal  factor,
const QSize 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 factor, and returns the result rounded to the nearest integer.

Definition at line 102 of file qsize.h.

◆ operator+

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

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

Definition at line 96 of file qsize.h.

◆ operator-

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

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

Definition at line 98 of file qsize.h.

◆ operator/

QSize QSize::operator/ ( const QSize 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 rounded to the nearest integer.

See also
QSize::scale()

Definition at line 104 of file qsize.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QSize 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 420 of file qsize.cpp.

Here is the call graph for this function:

◆ operator==

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

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

Definition at line 92 of file qsize.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QSize 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 439 of file qsize.cpp.

Here is the call graph for this function:

◆ qHash

constexpr friend size_t qHash ( const QSize s,
size_t  seed = 0 
)
friend

Definition at line 208 of file qsize.h.


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