| 1 |
import QtQuick 2.0 |
| 2 |
|
| 3 |
// positioning via anchors with a grid |
| 4 |
Rectangle { |
| 5 |
id: p |
| 6 |
color: "red" |
| 7 |
width: 400 |
| 8 |
height: 800 |
| 9 |
|
| 10 |
Rectangle { |
| 11 |
id: c |
| 12 |
color: "blue" |
| 13 |
anchors.top: p.verticalCenter |
| 14 |
anchors.bottom: p.bottom |
| 15 |
anchors.left: p.left |
| 16 |
anchors.right: p.right |
| 17 |
|
| 18 |
Grid { |
| 19 |
id: g |
| 20 |
rows: 2 |
| 21 |
columns: 2 |
| 22 |
anchors.top: c.verticalCenter |
| 23 |
anchors.bottom: c.bottom |
| 24 |
anchors.left: c.left |
| 25 |
anchors.right: c.right |
| 26 |
|
| 27 |
Rectangle { |
| 28 |
id: n1 |
| 29 |
color: "green" |
| 30 |
anchors.top: g.top |
| 31 |
anchors.bottom: g.verticalCenter |
| 32 |
anchors.left: g.left |
| 33 |
anchors.right: g.horizontalCenter |
| 34 |
} |
| 35 |
|
| 36 |
Rectangle { |
| 37 |
id: n2 |
| 38 |
color: "cyan" |
| 39 |
anchors.top: g.top |
| 40 |
anchors.bottom: g.verticalCenter |
| 41 |
anchors.left: g.horizontalCenter |
| 42 |
anchors.right: g.right |
| 43 |
} |
| 44 |
|
| 45 |
Rectangle { |
| 46 |
id: n3 |
| 47 |
color: "aquamarine" |
| 48 |
anchors.top: g.verticalCenter |
| 49 |
anchors.bottom: g.bottom |
| 50 |
anchors.left: g.left |
| 51 |
anchors.right: g.horizontalCenter |
| 52 |
} |
| 53 |
|
| 54 |
Rectangle { |
| 55 |
id: n4 |
| 56 |
color: "lightgreen" |
| 57 |
anchors.top: g.verticalCenter |
| 58 |
anchors.bottom: g.bottom |
| 59 |
anchors.left: g.horizontalCenter |
| 60 |
anchors.right: g.right |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
// for visually determining correctness. |
| 66 |
//Timer { |
| 67 |
// property int count: 0 |
| 68 |
// interval: 1000 |
| 69 |
// running: true |
| 70 |
// repeat: true |
| 71 |
// onTriggered: { |
| 72 |
// if (count == 0) { |
| 73 |
// count = 1; |
| 74 |
// p.height = 800; |
| 75 |
// } else { |
| 76 |
// count = 0; |
| 77 |
// p.height = 400; |
| 78 |
// } |
| 79 |
// } |
| 80 |
//} |
| 81 |
|
| 82 |
Component.onCompleted: { |
| 83 |
var iterations = 10000; |
| 84 |
//var t0 = new Date(); |
| 85 |
while (iterations > 0) { |
| 86 |
iterations--; |
| 87 |
p.height = 800; |
| 88 |
p.height = 400; |
| 89 |
} |
| 90 |
//var t1 = new Date(); |
| 91 |
//console.log("Anchor With Grid Positioning: " + (t1.valueOf() - t0.valueOf()) + " milliseconds"); |
| 92 |
} |
| 93 |
} |