Positioners and layouts in QML
There are different ways to position items in QML. You can manually position a control by mentioning x and y coordinates or by using anchors, positioners, or layouts. Let's discuss how to position a control through the aforementioned methods.
Manual positioning
A control can be positioned at specific x and y coordinates by setting their corresponding x and y properties. As per the visual coordinate system rules, this will position the controls relative to the top-left corner of their parent.
The following code snippet shows how to place a Rectangle
item at position (50,50
):
import QtQuick Rectangle { // Manually positioned at 50,50 x: 50 // x position y: 50 // y position width: 100; height: 80 color: "blue" }
When you run the preceding code, you will see a blue rectangle created at the (50,50
) position....