size QML Value Type

带有宽度和高度属性的值。更多

详细说明

size 类型指的是具有widthheight 属性的值。

size 类型的属性默认值为Qt.size(-1, -1)

例如,要读取Image::sourceSize size-type 属性的widthheight 值:

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

要创建size 值,请将其指定为 "宽 x 高 "字符串:

Image { sourceSize: "150x50" }

或使用Qt.size() 函数:

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

与 C++ 集成时,请注意从 C++ 传入 QML 的任何QSizeQSizeF 值都会自动转换为size 值,反之亦然。当size 值传入 C++ 时,会自动转换成QSizeF 值。

另请参阅 QML 值类型

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