IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QSizeF Class

The QSizeF class defines the size of a two-dimensional object using floating point precision.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QSizeF Class

  • Header: QSizeF

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Group: QSizeF is part of painting

Detailed Description

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 or equal to 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.

The QSizeF class also provides the toSize() function returning a QSize 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 Also

See also QSize, QPointF, QRectF

Member Function Documentation

 

[constexpr, since 5.14] QSizeF QSizeF::grownBy(QMarginsF margins) const

Returns the size that results from growing this size by margins.

This function was introduced in Qt 5.14.

See Also

See also shrunkBy()

[constexpr, since 5.14] QSizeF QSizeF::shrunkBy(QMarginsF margins) const

Returns the size that results from shrinking this size by margins.

This function was introduced in Qt 5.14.

See Also

See also grownBy()

[constexpr] QSizeF::QSizeF()

Constructs an invalid size.

See Also

See also isValid()

[constexpr] QSizeF::QSizeF(const QSize &size)

Constructs a size with floating point accuracy from the given size.

See Also

See also toSize(), QSize::toSizeF()

[constexpr] QSizeF::QSizeF(qreal width, qreal height)

Constructs a size with the given finite width and height.

[constexpr] QSizeF QSizeF::boundedTo(const QSizeF &otherSize) const

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

See Also

See also expandedTo(), scale()

[constexpr] QSizeF QSizeF::expandedTo(const QSizeF &otherSize) const

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

See Also

See also boundedTo(), scale()

[static, since 5.8] QSizeF QSizeF::fromCGSize(CGSize size)

Creates a QRectF from size.

This function was introduced in Qt 5.8.

See Also

See also toCGSize()

[constexpr] qreal QSizeF::height() const

Returns the height.

See Also

See also width(), setHeight()

[constexpr] bool QSizeF::isEmpty() const

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

See Also

See also isNull(), isValid()

bool QSizeF::isNull() const

Returns true if both the width and height are 0.0 (ignoring the sign); otherwise returns false.

See Also

See also isValid(), isEmpty()

[constexpr] bool QSizeF::isValid() const

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

See Also

See also isNull(), isEmpty()

[constexpr] qreal &QSizeF::rheight()

Returns a reference to the height.

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

 
Sélectionnez
QSizeF size(100, 10.2);
size.rheight() += 5.5;

// size becomes (100,15.7)
See Also

See also rwidth(), setHeight()

[constexpr] qreal &QSizeF::rwidth()

Returns a reference to the width.

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

 
Sélectionnez
QSizeF size(100.3, 10);
size.rwidth() += 20.5;

 // size becomes (120.8,10)
See Also

See also rheight(), setWidth()

void QSizeF::scale(qreal width, qreal height, Qt::AspectRatioMode mode)

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.

Example:

 
Sélectionnez
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 Also

See also setWidth(), setHeight(), scaled()

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

This is an overloaded function.

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

[since 5.0] QSizeF QSizeF::scaled(qreal width, qreal height, Qt::AspectRatioMode mode) const

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

This function was introduced in Qt 5.0.

See Also

See also scale()

[since 5.0] QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const

This is an overloaded function.

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

This function was introduced in Qt 5.0.

[constexpr] void QSizeF::setHeight(qreal height)

Sets the height to the given finite height.

See Also

See also height(), rheight(), setWidth()

[constexpr] void QSizeF::setWidth(qreal width)

Sets the width to the given finite width.

See Also

See also width(), rwidth(), setHeight()

[since 5.8] CGSize QSizeF::toCGSize() const

Creates a CGSize from a QSizeF.

This function was introduced in Qt 5.8.

See Also

See also fromCGSize()

[constexpr] 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 Also

See also QSizeF(), QSize::toSizeF()

void QSizeF::transpose()

Swaps the width and height values.

See Also

See also setWidth(), setHeight(), transposed()

[constexpr, since 5.0] QSizeF QSizeF::transposed() const

Returns the size with width and height values swapped.

This function was introduced in Qt 5.0.

See Also

See also transpose()

[constexpr] qreal QSizeF::width() const

Returns the width.

See Also

See also height(), setWidth()

[constexpr] QSizeF &QSizeF::operator*=(qreal factor)

This is an overloaded function.

Multiplies both the width and height by the given finite factor and returns a reference to the size.

See Also

See also scale()

[constexpr] QSizeF &QSizeF::operator+=(const QSizeF &size)

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

 
Sélectionnez
QSizeF s( 3, 7);
QSizeF r(-1, 4);
s += r;

// s becomes (2,11)

[constexpr] QSizeF &QSizeF::operator-=(const QSizeF &size)

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

 
Sélectionnez
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 given divisor and returns a reference to the size. The divisor must not be either zero or NaN.

See Also

See also scale()

Related Non-Members

 

[constexpr] bool operator!=(const QSizeF &s1, const QSizeF &s2)

Returns true if s1 and s2 are sufficiently different; otherwise returns false.

This function does not check for strict inequality; instead, it uses a fuzzy comparison to compare the sizes' extents.

[constexpr] QSizeF operator*(const QSizeF &size, qreal factor)

This is an overloaded function.

Multiplies the given size by the given finite factor and returns the result.

See Also

See also QSizeF::scale()

[constexpr] QSizeF operator*(qreal factor, const QSizeF &size)

This is an overloaded function.

Multiplies the given size by the given finite factor and returns the result.

[constexpr] QSizeF operator+(const QSizeF &s1, const QSizeF &s2)

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

[constexpr] QSizeF operator-(const QSizeF &s1, const QSizeF &s2)

Returns s2 subtracted from s1; each component is subtracted separately.

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

This is an overloaded function.

Divides the given size by the given divisor and returns the result. The divisor must not be either zero or NaN.

See Also

See also QSizeF::scale()

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

Writes the given size to the given stream and returns a reference to the stream.

See Also

[constexpr] bool operator==(const QSizeF &s1, const QSizeF &s2)

Returns true if s1 and s2 are approximately equal; otherwise returns false.

This function does not check for strict equality; instead, it uses a fuzzy comparison to compare the sizes' extents.

See Also

See also qFuzzyCompare

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

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

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+