Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QSize Class

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

Header:#include <QSize>

Public Functions

QSize()
QSize(int width, int height)
QSizeboundedTo(const QSize & otherSize) const
QSizeexpandedTo(const QSize & otherSize) const
intheight() const
boolisEmpty() const
boolisNull() const
boolisValid() const
int &rheight()
int &rwidth()
voidscale(int width, int height, Qt::AspectRatioMode mode)
voidscale(const QSize & size, Qt::AspectRatioMode mode)
voidsetHeight(int height)
voidsetWidth(int width)
voidtranspose()
intwidth() const
QSize &operator*=(qreal factor)
QSize &operator+=(const QSize & size)
QSize &operator-=(const QSize & size)
QSize &operator/=(qreal divisor)

Related Non-Members

booloperator!=(const QSize & s1, const QSize & s2)
const QSizeoperator*(qreal factor, const QSize & size)
const QSizeoperator*(const QSize & size, qreal factor)
const QSizeoperator+(const QSize & s1, const QSize & s2)
const QSizeoperator-(const QSize & s1, const QSize & s2)
const QSizeoperator/(const QSize & size, qreal divisor)
QDataStream &operator<<(QDataStream & stream, const QSize & size)
booloperator==(const QSize & s1, const QSize & s2)
QDataStream &operator>>(QDataStream & stream, QSize & size)

Detailed Description

TheQSize class defines the size of a two-dimensional object using integer point precision.

A size is specified by awidth() and aheight(). It can be set in the constructor and changed using thesetWidth(),setHeight(), orscale() functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using therwidth() andrheight() functions. Finally, the width and height can be swapped using thetranspose() function.

TheisValid() function determines if a size is valid (a valid size has both width and height greater than zero). TheisEmpty() function returns true if either of the width and height is less than, or equal to, zero, while theisNull() function returns true only if both the width and the height is zero.

Use theexpandedTo() function to retrieve a size which holds the maximum height and width ofthis size and a given size. Similarly, theboundedTo() function returns a size which holds the minimum height and width ofthis size and a given size.

QSize objects can be streamed as well as compared.

See alsoQSizeF,QPoint, andQRect.

Member Function Documentation

QSize::QSize()

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

See alsoisValid().

QSize::QSize(int width,int height)

Constructs a size with the givenwidth andheight.

See alsosetWidth() andsetHeight().

QSize QSize::boundedTo(constQSize & otherSize) const

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

See alsoexpandedTo() andscale().

QSize QSize::expandedTo(constQSize & otherSize) const

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

See alsoboundedTo() andscale().

int QSize::height() const

Returns the height.

See alsowidth() andsetHeight().

bool QSize::isEmpty() const

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

See alsoisNull() andisValid().

bool QSize::isNull() const

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

See alsoisValid() andisEmpty().

bool QSize::isValid() const

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

See alsoisNull() andisEmpty().

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)

See alsorwidth() andsetHeight().

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)

See alsorheight() andsetWidth().

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

Scales the size to a rectangle with the givenwidth andheight, according to the specifiedmode:

  • Ifmode isQt::IgnoreAspectRatio, the size is set to (width,height).
  • Ifmode isQt::KeepAspectRatio, the current size is scaled to a rectangle as large as possible inside (width,height), preserving the aspect ratio.
  • Ifmode isQt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle as small as possible outside (width,height), preserving the aspect ratio.

Example:

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 alsosetWidth() andsetHeight().

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

This is an overloaded function.

Scales the size to a rectangle with the givensize, according to the specifiedmode.

void QSize::setHeight(int height)

Sets the height to the givenheight.

See alsorheight(),height(), andsetWidth().

void QSize::setWidth(int width)

Sets the width to the givenwidth.

See alsorwidth(),width(), andsetHeight().

void QSize::transpose()

Swaps the width and height values.

See alsosetWidth() andsetHeight().

int QSize::width() const

Returns the width.

See alsoheight() andsetWidth().

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

This is an overloaded function.

Multiplies both the width and height by the givenfactor, and returns a reference to the size.

Note that the result is rounded to the nearest integer.

See alsoscale().

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

Adds the givensize tothis 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-=(constQSize & size)

Subtracts the givensize fromthis 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)

This is an overloaded function.

Divides both the width and height by the givendivisor, and returns a reference to the size.

Note that the result is rounded to the nearest integer.

See alsoQSize::scale().

Related Non-Members

booloperator!=(constQSize & s1, constQSize & s2)

Returns true ifs1 ands2 are different; otherwise returns false.

constQSizeoperator*(qreal factor, constQSize & size)

This is an overloaded function.

Multiplies the givensize by the givenfactor, and returns the result rounded to the nearest integer.

constQSizeoperator*(constQSize & size,qreal factor)

Multiplies the givensize by the givenfactor, and returns the result rounded to the nearest integer.

See alsoQSize::scale().

constQSizeoperator+(constQSize & s1, constQSize & s2)

Returns the sum ofs1 ands2; each component is added separately.

constQSizeoperator-(constQSize & s1, constQSize & s2)

Returnss2 subtracted froms1; each component is subtracted separately.

constQSizeoperator/(constQSize & size,qreal divisor)

This is an overloaded function.

Divides the givensize by the givendivisor, and returns the result rounded to the nearest integer.

See alsoQSize::scale().

QDataStream &operator<<(QDataStream & stream, constQSize & size)

Writes the givensize to the givenstream, and returns a reference to the stream.

See alsoSerializing Qt Data Types.

booloperator==(constQSize & s1, constQSize & s2)

Returns true ifs1 ands2 are equal; otherwise returns false.

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

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

See alsoSerializing Qt Data Types.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp