CopperSpice API  1.9.2
QSize Class Reference

Defines the size of a two-dimensional object using integer point precision. More...

Public Methods

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

Friends

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

Related Functions

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.

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

Constructor & Destructor Documentation

constexpr QSize::QSize ( )
inlineconstexpr

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

See also
isValid()
constexpr QSize::QSize ( int  width,
int  height 
)
inlineconstexpr

Constructs a size with the given width and height.

See also
setWidth(), setHeight()

Method Documentation

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

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

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

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

See also
boundedTo(), scale()
constexpr int QSize::height ( ) const
inlineconstexpr

Returns the height.

See also
width(), setHeight()
constexpr bool QSize::isEmpty ( ) const
inlineconstexpr

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

See also
isNull(), isValid()
constexpr bool QSize::isNull ( ) const
inlineconstexpr

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

See also
isValid(), isEmpty()
constexpr bool QSize::isValid ( ) const
inlineconstexpr

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

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

Multiplies both the width and height by the given factor and returns a reference to the size. The result is rounded to the nearest integer.

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

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

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

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

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

Divides both the width and height by the given factor and returns a reference to the size. The result is rounded to the nearest integer.

See also
QSize::scale()
int & QSize::rheight ( )
inline

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

QSize size(100, 10);
size.rheight() += 5;
// size becomes (100,15)
See also
rwidth(), setHeight()
int & QSize::rwidth ( )
inline

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

QSize size(100, 10);
size.rwidth() += 20;
// size becomes (120,10)
See also
rheight(), setWidth()
void QSize::scale ( const QSize &  size,
Qt::AspectRatioMode  mode 
)
inline

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

void QSize::scale ( int  width,
int  height,
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.
QSize t1(10, 12);
t1.scale(60, 60, Qt::IgnoreAspectRatio);
// t1 is (60, 60)
QSize t2(10, 12);
t2.scale(60, 60, Qt::KeepAspectRatio);
// t2 is (50, 60)
QSize t3(10, 12);
t3.scale(60, 60, Qt::KeepAspectRatioByExpanding);
// t3 is (60, 72)
See also
setWidth(), setHeight()
QSize QSize::scaled ( const QSize &  size,
Qt::AspectRatioMode  mode 
) const

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

QSize QSize::scaled ( int  width,
int  height,
Qt::AspectRatioMode  mode 
) const
inline

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

void QSize::setHeight ( int  height)
inline

Sets the height to the given height.

See also
rheight(), height(), setWidth()
void QSize::setWidth ( int  width)
inline

Sets the width to the given width.

See also
rwidth(), width(), setHeight()
void QSize::transpose ( )

Swaps the width and height values.

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

Returns a QSize with width and height swapped.

See also
transpose()
constexpr int QSize::width ( ) const
inlineconstexpr

Returns the width.

See also
height(), setWidth()

Friends And Related Function Documentation

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

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

const 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()
const QSize operator* ( qreal  factor,
const QSize &  size 
)
friend

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

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

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

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

Returns size2 subtracted from size1. Each component is subtracted separately.

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

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

See also
QSize::scale()
QDataStream & operator<< ( QDataStream stream,
const QSize &  size 
)
related

Writes the given size to the stream. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.

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

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

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

Reads from the stream into the given size. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.