QSize Class
La clase QSize define el tamaño de un objeto bidimensional utilizando precisión de punto entero. Más...
| Cabecera: | #include <QSize> |
| 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
- QSize es parte de Clases de Pintura.
Funciones Públicas
| QSize() | |
| QSize(int width, int height) | |
| QSize | boundedTo(const QSize &otherSize) const |
| QSize | expandedTo(const QSize &otherSize) const |
| QSize | grownBy(QMargins margins) 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) |
| QSize | shrunkBy(QMargins margins) const |
| CGSize | toCGSize() const |
(since 6.4) QSizeF | toSizeF() 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) |
No Miembros Relacionados
| bool | operator!=(const QSize &lhs, const QSize &rhs) |
| QSize | operator*(const QSize &size, qreal factor) |
| QSize | operator*(qreal factor, const QSize &size) |
| QSize | operator+(const QSize &s1, const QSize &s2) |
| QSize | operator-(const QSize &s1, const QSize &s2) |
| QSize | operator/(const QSize &size, qreal divisor) |
| QDataStream & | operator<<(QDataStream &stream, const QSize &size) |
| bool | operator==(const QSize &lhs, const QSize &rhs) |
| QDataStream & | operator>>(QDataStream &stream, QSize &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.
Los objetos QSize pueden transmitirse y compararse.
Véase también QSizeF, QPoint, y QRect.
Documentación de las funciones miembro
[constexpr noexcept] QSize::QSize()
Construye un tamaño con una anchura y altura no válidas (es decir, isValid() devuelve false).
Véase también isValid().
[constexpr noexcept] QSize::QSize(int width, int height)
Construye un tamaño con los datos width y height.
Véase también setWidth() y setHeight().
[constexpr noexcept] QSize QSize::boundedTo(const QSize &otherSize) const
Devuelve un tamaño que contiene la anchura y la altura mínimas de este tamaño y el otherSize dado.
Véase también expandedTo() y scale().
[constexpr noexcept] QSize QSize::expandedTo(const QSize &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().
[constexpr noexcept] QSize QSize::grownBy(QMargins margins) const
Devuelve el tamaño resultante de multiplicar este tamaño por margins.
Véase también shrunkBy().
[constexpr noexcept] int QSize::height() const
Devuelve la altura.
Ver también width() y setHeight().
[constexpr noexcept] bool QSize::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().
[constexpr noexcept] bool QSize::isNull() const
Devuelve true si tanto la anchura como la altura son 0; en caso contrario devuelve false.
Véase también isValid() y isEmpty().
[constexpr noexcept] bool QSize::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] int &QSize::rheight()
Devuelve una referencia a la altura.
El uso de una referencia permite manipular la altura directamente. Por ejemplo:
QSize size(100, 10); size.rheight() += 5; // size becomes (100,15)
Véase también rwidth() y setHeight().
[constexpr noexcept] int &QSize::rwidth()
Devuelve una referencia a la anchura.
El uso de una referencia permite manipular la anchura directamente. Por ejemplo:
QSize size(100, 10); size.rwidth() += 20; // size becomes (120,10)
Véase también rheight() y setWidth().
[noexcept] void QSize::scale(int width, int 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:
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)
Véase también setWidth(), setHeight() y scaled().
[noexcept] void QSize::scale(const QSize &size, Qt::AspectRatioMode mode)
Escala el tamaño a un rectángulo con la dirección size, de acuerdo con la dirección mode especificada.
Se trata de una función sobrecargada.
[noexcept] QSize QSize::scaled(int width, int 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] QSize QSize::scaled(const QSize &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 QSize::setHeight(int height)
Establece la altura en el valor height.
Véase también rheight(), height() y setWidth().
[constexpr noexcept] void QSize::setWidth(int width)
Establece la anchura en el valor width.
Véase también rwidth(), width() y setHeight().
[constexpr noexcept] QSize QSize::shrunkBy(QMargins margins) const
Devuelve el tamaño resultante de reducir este tamaño en margins.
Véase también grownBy().
[noexcept] CGSize QSize::toCGSize() const
Crea un CGSize a partir de un QSize.
Véase también QSizeF::fromCGSize().
[constexpr noexcept, since 6.4] QSizeF QSize::toSizeF() const
Devuelve este tamaño como un tamaño con precisión de coma flotante.
Esta función se introdujo en Qt 6.4.
Véase también QSizeF::toSize().
[noexcept] void QSize::transpose()
Intercambia los valores de anchura y altura.
Véase también setWidth(), setHeight() y transposed().
[constexpr noexcept] QSize QSize::transposed() const
Devuelve un QSize con la anchura y la altura intercambiadas.
Véase también transpose().
[constexpr noexcept] int QSize::width() const
Devuelve la anchura.
Véase también height() y setWidth().
[constexpr noexcept] QSize &QSize::operator*=(qreal factor)
Multiplica la anchura y la altura por factor y devuelve una referencia al tamaño.
Tenga en cuenta que el resultado se redondea al entero más próximo.
Véase también scale().
[constexpr noexcept] QSize &QSize::operator+=(const QSize &size)
Añade el size dado a este tamaño, y devuelve una referencia a este tamaño. Por ejemplo:
[constexpr noexcept] QSize &QSize::operator-=(const QSize &size)
Resta el size dado de este tamaño, y devuelve una referencia a este tamaño. Por ejemplo:
QSize &QSize::operator/=(qreal divisor)
Divide la anchura y la altura por el valor divisor y devuelve una referencia al tamaño.
Tenga en cuenta que el resultado se redondea al entero más próximo.
Véase también QSize::scale().
No miembros relacionados
[constexpr noexcept] bool operator!=(const QSize &lhs, const QSize &rhs)
Devuelve true si lhs y rhs son diferentes; en caso contrario devuelve false.
[constexpr noexcept] QSize operator*(const QSize &size, qreal factor)
Multiplica el size dado por el factor dado , y devuelve el resultado redondeado al entero más cercano.
Véase también QSize::scale().
[constexpr noexcept] QSize operator*(qreal factor, const QSize &size)
Multiplica el size dado por el factor dado , y devuelve el resultado redondeado al entero más cercano.
Se trata de una función sobrecargada.
[constexpr noexcept] QSize operator+(const QSize &s1, const QSize &s2)
Devuelve la suma de s1 y s2; cada componente se suma por separado.
[constexpr noexcept] QSize operator-(const QSize &s1, const QSize &s2)
Devuelve s2 restado de s1; cada componente se resta por separado.
QSize operator/(const QSize &size, qreal divisor)
Divide el size dado por el divisor dado , y devuelve el resultado redondeado al entero más cercano.
Véase también QSize::scale().
QDataStream &operator<<(QDataStream &stream, const QSize &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 QSize &lhs, const QSize &rhs)
Devuelve true si lhs y rhs son iguales; en caso contrario devuelve false.
QDataStream &operator>>(QDataStream &stream, QSize &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.