QSize 类

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

Header: #include <QSize>
qmake: QT += core

公共函数

QSize ()
QSize (int width , int height )
QSize boundedTo (const QSize & otherSize ) const
QSize expandedTo (const QSize & otherSize ) const
int height () const
bool isEmpty () const
bool isNull () const
bool isValid () const
int & rheight ()
int & rwidth ()
void scale (int width , int height , Qt::AspectRatioMode mode )
void scale (const QSize & size , Qt::AspectRatioMode mode )
QSize scaled (int width , int height , Qt::AspectRatioMode mode ) const
QSize scaled (const QSize & s , Qt::AspectRatioMode mode ) const
void setHeight (int height )
void setWidth (int width )
CGSize toCGSize () const
void transpose ()
QSize transposed () const
int width () const
QSize & operator*= (qreal factor )
QSize & operator+= (const QSize & size )
QSize & operator-= (const QSize & size )
QSize & operator/= (qreal divisor )
bool operator!= (const QSize & s1 , const QSize & s2 )
const QSize operator* (const QSize & size , qreal factor )
const QSize operator* (qreal factor , const QSize & size )
const QSize operator+ (const QSize & s1 , const QSize & s2 )
const QSize operator- (const QSize & s1 , const QSize & s2 )
const QSize operator/ (const QSize & size , qreal divisor )
QDataStream & operator<< (QDataStream & stream , const QSize & size )
bool operator== (const QSize & s1 , const QSize & s2 )
QDataStream & operator>> (QDataStream & stream , QSize & size )

详细描述

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 (),或 scale () functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using the rwidth () 和 rheight () functions. Finally, the width and height can be swapped using the transpose () 函数。

isValid () function determines if a size is valid (a valid size has both width and height greater than or equal to zero). The isEmpty () 函数返回 true if either of the width and height is less than, or equal to, zero, while the isNull () 函数返回 true only if both the width and the height is zero.

使用 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.

另请参阅 QSizeF , QPoint ,和 QRect .

成员函数文档编制

QSize:: QSize ()

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

另请参阅 isValid ().

QSize:: QSize ( int width , int height )

构造尺寸,采用给定 width and height .

另请参阅 setWidth () 和 setHeight ().

QSize QSize:: boundedTo (const QSize & otherSize ) const

返回尺寸,该尺寸保持最小宽度 高度,及给定 otherSize .

另请参阅 expandedTo () 和 scale ().

QSize QSize:: expandedTo (const QSize & otherSize ) const

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

另请参阅 boundedTo () 和 scale ().

int QSize:: height () const

返回高度。

另请参阅 width () 和 setHeight ().

bool QSize:: isEmpty () const

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

另请参阅 isNull () 和 isValid ().

bool QSize:: isNull () const

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

另请参阅 isValid () 和 isEmpty ().

bool QSize:: isValid () const

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

另请参阅 isNull () 和 isEmpty ().

int &QSize:: rheight ()

Returns a reference to the height.

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

QSize size(100, 10);
size.rheight() += 5;
// size becomes (100,15)
							

另请参阅 rwidth () 和 setHeight ().

int &QSize:: rwidth ()

Returns a reference to the width.

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

QSize size(100, 10);
size.rwidth() += 20;
// size becomes (120,10)
							

另请参阅 rheight () 和 setWidth ().

void QSize:: scale ( int width , int height , Qt::AspectRatioMode mode )

把尺寸缩放到矩形,采用给定 width and height ,根据指定 mode :

  • mode is Qt::IgnoreAspectRatio , the size is set to ( width , height ).
  • mode is Qt::KeepAspectRatio , the current size is scaled to a rectangle as large as possible inside ( width , height ), preserving the aspect ratio.
  • 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)
							

另请参阅 setWidth (), setHeight (),和 scaled ().

void QSize:: scale (const QSize & size , Qt::AspectRatioMode mode )

这是重载函数。

把尺寸缩放到矩形,采用给定 size ,根据指定 mode .

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

Return a size scaled to a rectangle with the given width and height ,根据指定 mode .

This function was introduced in Qt 5.0.

另请参阅 scale ().

QSize QSize:: scaled (const QSize & s , Qt::AspectRatioMode mode ) const

这是重载函数。

Return a size scaled to a rectangle with the given size s ,根据指定 mode .

This function was introduced in Qt 5.0.

void QSize:: setHeight ( int height )

Sets the height to the given height .

另请参阅 rheight (), height (),和 setWidth ().

void QSize:: setWidth ( int width )

Sets the width to the given width .

另请参阅 rwidth (), width (),和 setHeight ().

CGSize QSize:: toCGSize () const

创建 CGSize,从 QSize .

This function was introduced in Qt 5.8.

另请参阅 QSizeF::fromCGSize ().

void QSize:: transpose ()

Swaps the width and height values.

另请参阅 setWidth (), setHeight (),和 transposed ().

QSize QSize:: transposed () const

返回 QSize with width and height swapped.

This function was introduced in Qt 5.0.

另请参阅 transpose ().

int QSize:: width () const

返回宽度。

另请参阅 height () 和 setWidth ().

QSize &QSize:: operator*= ( qreal factor )

这是重载函数。

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.

另请参阅 scale ().

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

添加给定 size to this size, and returns a reference to this size. For example:

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

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

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

QSize s( 3, 7);
QSize r(-1, 4);
s -= r;
// s becomes (4,3)
							

QSize &QSize:: operator/= ( qreal divisor )

这是重载函数。

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.

另请参阅 QSize::scale ().

相关非成员

bool operator!= (const QSize & s1 , const QSize & s2 )

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

const QSize operator* (const QSize & size , qreal factor )

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

另请参阅 QSize::scale ().

const QSize operator* ( qreal factor , const QSize & size )

这是重载函数。

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

const QSize operator+ (const QSize & s1 , const QSize & s2 )

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

const QSize operator- (const QSize & s1 , const QSize & s2 )

返回 s2 subtracted from s1 ; each component is subtracted separately.

const QSize operator/ (const QSize & size , qreal divisor )

这是重载函数。

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

另请参阅 QSize::scale ().

QDataStream & operator<< ( QDataStream & stream , const QSize & size )

写入给定 size 到给定 stream , and returns a reference to the stream.

另请参阅 序列化 Qt 数据类型 .

bool operator== (const QSize & s1 , const QSize & s2 )

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

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

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

另请参阅 序列化 Qt 数据类型 .