QSize 类

QSize 类使用整数点精度定义 2D 对象的大小。 更多...

头: #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 类使用整数点精度定义 2D 对象的大小。

尺寸的指定通过 width () 和 height ()。可以在构造函数中设置它和改变使用 setWidth (), setHeight (),或 scale () 函数,或使用算术运算符。也可以直接操纵尺寸通过检索宽度和高度的引用使用 rwidth () 和 rheight () 函数。最后,可以交换宽度和高度使用 transpose () 函数。

isValid () 函数确定尺寸是否有效 (有效尺寸拥有的宽度和高度两者大于或等于 0)。 isEmpty () 函数返回 true 若宽度和高度任一小于或等于 0,而 isNull () 函数返回 true 仅当宽度和高度两者为 0 时。

使用 expandedTo () 函数以检索尺寸保持的最大高度和宽度为 this 尺寸和给定尺寸。同样, boundedTo () 函数返回的尺寸保持最小高度 宽度为 this 尺寸和给定尺寸。

QSize 对象可以被流化及比较。

另请参阅 QSizeF , QPoint ,和 QRect .

成员函数文档编制

QSize:: QSize ()

采用无效宽度和高度构造尺寸 (即 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

返回的尺寸保持此尺寸的最大宽度 高度和给定 otherSize .

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

int QSize:: height () const

返回高度。

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

bool QSize:: isEmpty () const

返回 true 若宽度和高度两者任一 <= 0;否则返回 false .

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

bool QSize:: isNull () const

返回 true 若宽度和高度两者为 0;否则返回 false。

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

bool QSize:: isValid () const

返回 true 若宽度和高度两者 >= 0;否则返回 false .

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

int &QSize:: rheight ()

返回高度的引用。

使用引用使直接操纵高度成为可能。例如:

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

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

int &QSize:: rwidth ()

返回宽度的引用。

使用引用使直接操纵宽度成为可能。例如:

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 ,尺寸被设为 ( 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

返回的尺寸比例缩放到矩形采用给定 width and height ,根据指定 mode .

该函数在 Qt 5.0 引入。

另请参阅 scale ().

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

这是重载函数。

返回的尺寸比例缩放到矩形采用给定尺寸 s ,根据指定 mode .

该函数在 Qt 5.0 引入。

void QSize:: setHeight ( int height )

将高度设为给定 height .

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

void QSize:: setWidth ( int width )

将宽度设为给定 width .

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

CGSize QSize:: toCGSize () const

创建 CGSize 从 QSize .

该函数在 Qt 5.8 引入。

另请参阅 QSizeF::fromCGSize ().

void QSize:: transpose ()

交换宽度和高度值。

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

QSize QSize:: transposed () const

返回 QSize 具有交换的宽度和高度。

该函数在 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 )

减去给定 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 通过给定 factor , and returns the result rounded to the nearest integer.

另请参阅 QSize::scale ().

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

这是重载函数。

Multiplies the given size 通过给定 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 ;分别相加各分量。

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

返回 s2 subtracted from s1 ;分别减去各分量。

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

这是重载函数。

Divides the given size 通过给定 divisor , and returns the result rounded to the nearest integer.

另请参阅 QSize::scale ().

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

写入给定 size 到给定 stream ,并返回流引用。

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

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

返回 true if s1 and s2 相等;否则返回 false .

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

Reads a size from the given stream 进给定 size ,并返回流引用。

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