Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
coordinates.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquick-visualcanvas-coordinates.html
6
\title Concepts - Visual Coordinates in Qt Quick
7
\brief Description of the concept of visual coordinates in Qt Quick
8
9
\section1 Item Coordinates
10
The default system of visual coordinates used in Qt Quick is item coordinates. This is a cartesian coordinate system
11
with (0,0) at the top left corner of the item. The x-axis grows to the right and the y-axis grows downwards, so that
12
the bottom right corner of the item is at coordinates (width, height).
13
14
An individual item's position is specified in terms of its parent's coordinate system. This means that reading x,y
15
values from non-sibling items may require conversion to convert them into the same coordinate system. Scene
16
coordinates are often used as the intermediate coordinate system when this occurs.
17
18
\section1 Scene Coordinates
19
Scene coordinates are the coordinates where (0,0) corresponds to the top left corner of the window the scene is
20
currently being rendered. Scene coordinates are usually the same as the item coordinates of the root item in the
21
window.
22
23
You can convert from item to scene coordinates using the functions on the item whose coordinate system you are
24
interested in. See \l Item::mapFromItem and \l Item::mapToItem for converting to scene coordinates, or another item's
25
coordinates.
26
27
\section1 Worked Example
28
The below QML code creates an arrangment of squares, with dots added for identification of points:
29
\code
30
Rectangle {
31
width: 200
32
height: 200
33
color: "red"
34
35
Rectangle {
36
x: 100
37
y: 100
38
width: 100
39
height: 100
40
color: "blue"
41
42
Rectangle {
43
width: 50
44
height: 50
45
color: "green"
46
}
47
}
48
}
49
\endcode
50
51
\image visual-coordinates-example.png
52
53
In this image the black dot is positioned at (0,0) within the item coordinates of the red rectangle. If the red
54
rectangle was the root item of the scene, then the black dot would also be positioned at (0,0) in scene coordinates.
55
56
The blue rectangle is positioned at the white dot, (100,100), relative to the red rectangle's top left corner.
57
58
The green rectangle has no x,y specified, so its position defaults to (0,0). Because it is at (0,0) in the coordinates of its parent,
59
the blue rectangle, it is positioned at the top left corner of that rectangle. This is the same point as the white dot at
60
(100,100) in the coordinates of the red rectangle.
61
62
*/
qtdeclarative
src
quick
doc
src
concepts
visualcanvas
coordinates.qdoc
Generated on
for Qt by
1.14.0