En esta página

size QML Value Type

un valor con los atributos «width» y «height». Más...

Import Statement: import QtQml

Descripción detallada

El tipo « size » hace referencia a un valor que tiene los atributos « width » y « height ».

Las propiedades de tipo « size » tienen « Qt.size(-1, -1) » como valor por defecto.

Por ejemplo, para leer los valores de « width » y « height » de la propiedad de tipo « Image::sourceSize »:

Column {
    Image { id: image; source: "logo.png" }
    Text { text: image.sourceSize.width + "," + image.sourceSize.height }
}

Para crear un valor « size », especifícalo como una cadena del tipo «anchura x altura»:

Image { sourceSize: "150x50" }

O bien, utiliza la función Qt.size():

Image { sourceSize: Qt.size(150, 50) }

Al integrar con C++, ten en cuenta que cualquier valor de tipo « QSize » o « QSizeF » pasado a QML desde C++ se convierte automáticamente en un valor de tipo « size », y viceversa. Cuando se pasa un valor de tipo « size » a C++, se convierte automáticamente en un valor de tipo « QSizeF ».

Véase también «Tipos de valor deQML».

© 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.