Nesta página

rect QML Value Type

um valor com os atributos x, y, largura e altura. Mais...

Import Statement: import QtQml

Descrição detalhada

O tipo ` rect ` refere-se a um valor com os atributos ` x`, ` y`, ` width ` e ` height `.

As propriedades do tipo ` rect ` são ` Qt.rect(0, 0, 0, 0) ` por padrão. Trata-se de um retângulo vazio na origem das coordenadas.

Por exemplo, para ler os valores de ` width ` e ` height ` da propriedade de tipo retângulo ` Item ` ` childrenRect `:

Rectangle {
    width: childrenRect.width
    height: childrenRect.height

    Rectangle { width: 100; height: 100 }
}

Para criar um valor rect, especifique-o como uma string no formato “x, y, largura x altura”:

CustomObject { myRectProperty: "50,50,100x100" }

Ou use a função ` Qt.rect()`:

CustomObject { myRectProperty: Qt.rect(50, 50, 100, 100) }

O tipo ` rect ` também expõe os atributos somente leitura ` left`, ` right`, ` top ` e ` bottom `. Esses são iguais aos seus equivalentes no ` C++ counterparts`.

Ao integrar com C++, observe que qualquer valor do tipo ` QRect ` ou ` QRectF ` passado do C++ para o QML é automaticamente convertido em um valor do tipo ` rect `, e vice-versa. Quando um valor do tipo ` rect ` é passado para o C++, ele é automaticamente convertido em um valor do tipo ` QRectF `.

Veja também Tipos de valor do QML.

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