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

QSizeF Class

TheQSizeF class defines the size of a two-dimensional object using floating point precision.More...

Header:#include <QSizeF>

Public Functions

QSizeF()
QSizeF(const QSize & size)
QSizeF(qreal width, qreal height)
QSizeFboundedTo(const QSizeF & otherSize) const
QSizeFexpandedTo(const QSizeF & otherSize) const
qrealheight() const
boolisEmpty() const
boolisNull() const
boolisValid() const
qreal &rheight()
qreal &rwidth()
voidscale(qreal width, qreal height, Qt::AspectRatioMode mode)
voidscale(const QSizeF & size, Qt::AspectRatioMode mode)
voidsetHeight(qreal height)
voidsetWidth(qreal width)
QSizetoSize() const
voidtranspose()
qrealwidth() const
QSizeF &operator*=(qreal factor)
QSizeF &operator+=(const QSizeF & size)
QSizeF &operator-=(const QSizeF & size)
QSizeF &operator/=(qreal divisor)

Related Non-Members

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

Detailed Description

TheQSizeF class defines the size of a two-dimensional object using floating 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 or equal to zero. TheisEmpty() function returns true if either of the width and height isless 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 of this size and a given size. Similarly, theboundedTo() function returns a size which holds the minimum height and width of this size and a given size.

TheQSizeF class also provides thetoSize() function returning aQSize copy of this size, constructed by rounding the width and height to the nearest integers.

QSizeF objects can be streamed as well as compared.

See alsoQSize,QPointF, andQRectF.

Member Function Documentation

QSizeF::QSizeF()

Constructs an invalid size.

See alsoisValid().

QSizeF::QSizeF(constQSize & size)

Constructs a size with floating point accuracy from the givensize.

See alsotoSize().

QSizeF::QSizeF(qreal width,qreal height)

Constructs a size with the givenwidth andheight.

QSizeF QSizeF::boundedTo(constQSizeF & otherSize) const

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

See alsoexpandedTo() andscale().

QSizeF QSizeF::expandedTo(constQSizeF & otherSize) const

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

See alsoboundedTo() andscale().

qreal QSizeF::height() const

Returns the height.

See alsowidth() andsetHeight().

bool QSizeF::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 QSizeF::isNull() const

Returns true if both the width and height are +0.0; otherwise returns false.

Note:Since this function treats +0.0 and -0.0 differently, sizes with zero width and height where either or both values have a negative sign are not defined to be null sizes.

See alsoisValid() andisEmpty().

bool QSizeF::isValid() const

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

See alsoisNull() andisEmpty().

qreal & QSizeF::rheight()

Returns a reference to the height.

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

QSizeF size(100,10.2);size.rheight()+=5.5;// size becomes (100,15.7)

See alsorwidth() andsetHeight().

qreal & QSizeF::rwidth()

Returns a reference to the width.

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

QSizeF size(100.3,10);size.rwidth()+=20.5;// size becomes (120.8,10)

See alsorheight() andsetWidth().

void QSizeF::scale(qreal width,qreal 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:

QSizeF t1(10,12);t1.scale(60,60,Qt::IgnoreAspectRatio);// t1 is (60, 60)QSizeF t2(10,12);t2.scale(60,60,Qt::KeepAspectRatio);// t2 is (50, 60)QSizeF t3(10,12);t3.scale(60,60,Qt::KeepAspectRatioByExpanding);// t3 is (60, 72)

See alsosetWidth() andsetHeight().

void QSizeF::scale(constQSizeF & size,Qt::AspectRatioMode mode)

This is an overloaded function.

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

void QSizeF::setHeight(qreal height)

Sets the height to the givenheight.

See alsoheight(),rheight(), andsetWidth().

void QSizeF::setWidth(qreal width)

Sets the width to the givenwidth.

See alsowidth(),rwidth(), andsetHeight().

QSize QSizeF::toSize() const

Returns an integer based copy of this size.

Note that the coordinates in the returned size will be rounded to the nearest integer.

See alsoQSizeF().

void QSizeF::transpose()

Swaps the width and height values.

See alsosetWidth() andsetHeight().

qreal QSizeF::width() const

Returns the width.

See alsoheight() andsetWidth().

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

This is an overloaded function.

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

See alsoscale().

QSizeF & QSizeF::operator+=(constQSizeF & size)

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

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

QSizeF & QSizeF::operator-=(constQSizeF & size)

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

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

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

This is an overloaded function.

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

See alsoscale().

Related Non-Members

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

Returns true ifs1 ands2 are different; otherwise returns false.

constQSizeFoperator*(constQSizeF & size,qreal factor)

This is an overloaded function.

Multiplies the givensize by the givenfactor and returns the result.

See alsoQSizeF::scale().

constQSizeFoperator*(qreal factor, constQSizeF & size)

This is an overloaded function.

Multiplies the givensize by the givenfactor and returns the result.

constQSizeFoperator+(constQSizeF & s1, constQSizeF & s2)

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

constQSizeFoperator-(constQSizeF & s1, constQSizeF & s2)

Returnss2 subtracted froms1; each component is subtracted separately.

constQSizeFoperator/(constQSizeF & size,qreal divisor)

This is an overloaded function.

Divides the givensize by the givendivisor and returns the result.

See alsoQSizeF::scale().

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

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

See alsoSerializing Qt Data Types.

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

Returns true ifs1 ands2 are equal; otherwise returns false.

QDataStream &operator>>(QDataStream & stream,QSizeF & 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