QSizeF Class
La clase QSizeF define el tamaño de un objeto bidimensional utilizando precisión de coma flotante. Más...
| Cabecera: | #include <QSizeF> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core)target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
- Lista de todos los miembros, incluyendo los heredados
- QSizeF es parte de Clases de Pintura.
Funciones Públicas
| QSizeF() | |
| QSizeF(const QSize &size) | |
| QSizeF(qreal width, qreal height) | |
| QSizeF | boundedTo(const QSizeF &otherSize) const |
| QSizeF | expandedTo(const QSizeF &otherSize) const |
| QSizeF | grownBy(QMarginsF margins) const |
| qreal | height() const |
| bool | isEmpty() const |
| bool | isNull() const |
| bool | isValid() const |
| qreal & | rheight() |
| qreal & | rwidth() |
| void | scale(qreal width, qreal height, Qt::AspectRatioMode mode) |
| void | scale(const QSizeF &size, Qt::AspectRatioMode mode) |
| QSizeF | scaled(qreal width, qreal height, Qt::AspectRatioMode mode) const |
| QSizeF | scaled(const QSizeF &s, Qt::AspectRatioMode mode) const |
| void | setHeight(qreal height) |
| void | setWidth(qreal width) |
| QSizeF | shrunkBy(QMarginsF margins) const |
| CGSize | toCGSize() const |
| QSize | toSize() const |
| void | transpose() |
| QSizeF | transposed() const |
| qreal | width() const |
| QSizeF & | operator*=(qreal factor) |
| QSizeF & | operator+=(const QSizeF &size) |
| QSizeF & | operator-=(const QSizeF &size) |
| QSizeF & | operator/=(qreal divisor) |
Miembros Públicos Estáticos
| QSizeF | fromCGSize(CGSize size) |
No Miembros Relacionados
(since 6.8) bool | qFuzzyCompare(const QSizeF &lhs, const QSizeF &rhs) |
(since 6.8) bool | qFuzzyIsNull(const QSizeF &size) |
| bool | operator!=(const QSizeF &lhs, const QSizeF &rhs) |
| QSizeF | operator*(const QSizeF &size, qreal factor) |
| QSizeF | operator*(qreal factor, const QSizeF &size) |
| QSizeF | operator+(const QSizeF &s1, const QSizeF &s2) |
| QSizeF | operator-(const QSizeF &s1, const QSizeF &s2) |
| QSizeF | operator/(const QSizeF &size, qreal divisor) |
| QDataStream & | operator<<(QDataStream &stream, const QSizeF &size) |
| bool | operator==(const QSizeF &lhs, const QSizeF &rhs) |
| QDataStream & | operator>>(QDataStream &stream, QSizeF &size) |
Descripción Detallada
El tamaño se especifica mediante width() y height(). Puede establecerse en el constructor y cambiarse utilizando las funciones setWidth(), setHeight(), o scale(), o utilizando operadores aritméticos. Un tamaño también puede manipularse directamente recuperando referencias a la anchura y la altura mediante las funciones rwidth() y rheight(). Por último, la anchura y la altura pueden intercambiarse mediante la función transpose().
La función isValid() determina si un tamaño es válido. Un tamaño válido tiene tanto la anchura como la altura mayores o iguales que cero. La función isEmpty() devuelve true si la anchura y la altura son menores (o iguales) que cero, mientras que la función isNull() devuelve true sólo si tanto la anchura como la altura son cero.
Utilice la función expandedTo() para recuperar un tamaño que contenga la altura y la anchura máximas de este tamaño y de un tamaño dado. Del mismo modo, la función boundedTo() devuelve un tamaño que contiene la altura y anchura mínimas de este tamaño y un tamaño dado.
La clase QSizeF también proporciona la función toSize() que devuelve una copia QSize de este tamaño, construida redondeando la anchura y la altura a los enteros más cercanos.
Los objetos QSizeF pueden compararse y transmitirse.
Véase también QSize, QPointF, y QRectF.
Documentación de las funciones miembro
[constexpr noexcept] QSizeF::QSizeF()
Construye un tamaño inválido.
Véase también isValid().
[constexpr noexcept] QSizeF::QSizeF(const QSize &size)
Construye un tamaño con precisión de coma flotante a partir de la dirección size.
Véase también toSize() y QSize::toSizeF().
[constexpr noexcept] QSizeF::QSizeF(qreal width, qreal height)
Construye un tamaño con el finito dado width y height.
[constexpr noexcept] QSizeF QSizeF::boundedTo(const QSizeF &otherSize) const
Devuelve un tamaño que contiene la anchura y altura mínimas de este tamaño y el otherSize dado.
Véase también expandedTo() y scale().
[constexpr noexcept] QSizeF QSizeF::expandedTo(const QSizeF &otherSize) const
Devuelve un tamaño que contiene la anchura y altura máximas de este tamaño y el otherSize dado.
Véase también boundedTo() y scale().
[static noexcept] QSizeF QSizeF::fromCGSize(CGSize size)
Crea un QSizeF a partir de size.
Véase también toCGSize().
[constexpr noexcept] QSizeF QSizeF::grownBy(QMarginsF margins) const
Devuelve el tamaño resultante de multiplicar este tamaño por margins.
Véase también shrunkBy().
[constexpr noexcept] qreal QSizeF::height() const
Devuelve la altura.
Ver también width() y setHeight().
[constexpr noexcept] bool QSizeF::isEmpty() const
Devuelve true si cualquiera de los valores de anchura y altura es menor o igual que 0; en caso contrario, devuelve false.
Véase también isNull() y isValid().
[noexcept] bool QSizeF::isNull() const
Devuelve true si tanto la anchura como la altura son 0,0 (ignorando el signo); en caso contrario devuelve false.
Véase también isValid() y isEmpty().
[constexpr noexcept] bool QSizeF::isValid() const
Devuelve true si tanto la anchura como la altura son iguales o mayores que 0; en caso contrario devuelve false.
Véase también isNull() y isEmpty().
[constexpr noexcept] qreal &QSizeF::rheight()
Devuelve una referencia a la altura.
El uso de una referencia permite manipular la altura directamente. Por ejemplo:
QSizeF size(100, 10.2); size.rheight() += 5.5; // size becomes (100,15.7)
Véase también rwidth() y setHeight().
[constexpr noexcept] qreal &QSizeF::rwidth()
Devuelve una referencia a la anchura.
El uso de una referencia permite manipular la anchura directamente. Por ejemplo:
QSizeF size(100.3, 10); size.rwidth() += 20.5; // size becomes (120.8,10)
Véase también rheight() y setWidth().
[noexcept] void QSizeF::scale(qreal width, qreal height, Qt::AspectRatioMode mode)
Escala el tamaño a un rectángulo con los valores dados width y height, según el valor especificado mode.
- Si mode es Qt::IgnoreAspectRatio, el tamaño se establece en (width, height).
- Si mode es Qt::KeepAspectRatio, el tamaño actual se escala a un rectángulo lo más grande posible dentro de (width, height), preservando la relación de aspecto.
- Si mode es Qt::KeepAspectRatioByExpanding, el tamaño actual se ajusta a un rectángulo lo más pequeño posible fuera de (width, height), conservando la relación de aspecto.
Ejemplo:
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)
Véase también setWidth(), setHeight() y scaled().
[noexcept] void QSizeF::scale(const QSizeF &size, Qt::AspectRatioMode mode)
Escala el tamaño a un rectángulo con el valor dado size, de acuerdo con el valor especificado mode.
Se trata de una función sobrecargada.
[noexcept] QSizeF QSizeF::scaled(qreal width, qreal height, Qt::AspectRatioMode mode) const
Devuelve un tamaño escalado a un rectángulo con los valores dados width y height, según el valor especificado mode.
Véase también scale().
[noexcept] QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const
Devuelve un tamaño escalado a un rectángulo con el tamaño dado s, según el mode especificado.
Se trata de una función sobrecargada.
[constexpr noexcept] void QSizeF::setHeight(qreal height)
Establece la altura en el finito dado height.
Véase también height(), rheight() y setWidth().
[constexpr noexcept] void QSizeF::setWidth(qreal width)
Establece el ancho al finito dado width.
Véase también width(), rwidth() y setHeight().
[constexpr noexcept] QSizeF QSizeF::shrunkBy(QMarginsF margins) const
Devuelve el tamaño resultante de reducir este tamaño en margins.
Véase también grownBy().
[noexcept] CGSize QSizeF::toCGSize() const
Crea un CGSize a partir de un QSizeF.
Véase también fromCGSize().
[constexpr noexcept] QSize QSizeF::toSize() const
Devuelve una copia basada en enteros de este tamaño.
Tenga en cuenta que las coordenadas del tamaño devuelto se redondearán al entero más cercano.
Véase también QSizeF() y QSize::toSizeF().
[noexcept] void QSizeF::transpose()
Intercambia los valores de anchura y altura.
Véase también setWidth(), setHeight() y transposed().
[constexpr noexcept] QSizeF QSizeF::transposed() const
Devuelve el tamaño con los valores de anchura y altura intercambiados.
Véase también transpose().
[constexpr noexcept] qreal QSizeF::width() const
Devuelve la anchura.
Véase también height() y setWidth().
[constexpr noexcept] QSizeF &QSizeF::operator*=(qreal factor)
Multiplica la anchura y la altura por el valor finito factor y devuelve una referencia al tamaño.
Véase también scale().
[constexpr noexcept] QSizeF &QSizeF::operator+=(const QSizeF &size)
Añade el size dado a este tamaño y devuelve una referencia a este tamaño. Por ejemplo:
[constexpr noexcept] QSizeF &QSizeF::operator-=(const QSizeF &size)
Resta el size dado de este tamaño y devuelve una referencia a este tamaño. Por ejemplo:
QSizeF &QSizeF::operator/=(qreal divisor)
Divide la anchura y la altura por el valor divisor y devuelve una referencia al tamaño. divisor no debe ser cero ni NaN.
Véase también scale().
No miembros relacionados
[constexpr noexcept, since 6.8] bool qFuzzyCompare(const QSizeF &lhs, const QSizeF &rhs)
Devuelve true si el tamaño lhs es aproximadamente igual al tamaño rhs; en caso contrario devuelve false.
Los tamaños se consideran aproximadamente iguales si su anchura y altura son aproximadamente iguales.
Esta función se introdujo en Qt 6.8.
[constexpr noexcept, since 6.8] bool qFuzzyIsNull(const QSizeF &size)
Devuelve true si tanto la anchura como la altura del tamaño size son aproximadamente iguales a cero.
Esta función se introdujo en Qt 6.8.
[constexpr noexcept] bool operator!=(const QSizeF &lhs, const QSizeF &rhs)
Devuelve true si lhs y rhs son suficientemente diferentes; en caso contrario devuelve false.
Advertencia: Esta función no comprueba la desigualdad estricta; en su lugar, utiliza una comparación difusa para comparar las extensiones de los tamaños.
[constexpr noexcept] QSizeF operator*(const QSizeF &size, qreal factor)
Multiplica el size dado por el factor finito dado y devuelve el resultado.
Se trata de una función sobrecargada.
Véase también QSizeF::scale().
[constexpr noexcept] QSizeF operator*(qreal factor, const QSizeF &size)
Multiplica el size dado por el factor finito dado y devuelve el resultado.
Se trata de una función sobrecargada.
[constexpr noexcept] QSizeF operator+(const QSizeF &s1, const QSizeF &s2)
Devuelve la suma de s1 y s2; cada componente se suma por separado.
[constexpr noexcept] QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
Devuelve s2 restado de s1; cada componente se resta por separado.
QSizeF operator/(const QSizeF &size, qreal divisor)
Divide el size dado por el divisor dado y devuelve el resultado. divisor no debe ser cero ni NaN.
Véase también QSizeF::scale().
QDataStream &operator<<(QDataStream &stream, const QSizeF &size)
Escribe el size dado en el stream dado y devuelve una referencia al flujo.
Véase también Serializar tipos de datos Qt.
[constexpr noexcept] bool operator==(const QSizeF &lhs, const QSizeF &rhs)
Devuelve true si lhs y rhs son aproximadamente iguales; en caso contrario devuelve false.
Advertencia: Esta función no comprueba la igualdad estricta; en su lugar, utiliza una comparación difusa para comparar las extensiones de los tamaños.
Véase también qFuzzyCompare.
QDataStream &operator>>(QDataStream &stream, QSizeF &size)
Lee un tamaño del stream dado en el size dado y devuelve una referencia al flujo.
Véase también Serializar tipos de datos Qt.
© 2026 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 the GNU 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.