User Tools

Site Tools


qt-quick-for-designers-1:positioning_elements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
qt-quick-for-designers-1:positioning_elements [2013/06/21 22:49] – created mithatqt-quick-for-designers-1:positioning_elements [2013/07/06 21:25] mithat
Line 1: Line 1:
 ====== Positioning elements ====== ====== Positioning elements ======
  
 +===== Absolute positioning =====
 +{{dailymotion>x11la0b?small}}
 +
 +    * You can define an item's position and size within its parent.
 +<file javascript basic-positioners.qml>
 import QtQuick 1.0 import QtQuick 1.0
  
Line 8: Line 13:
  
     Image {     Image {
 +        anchors.fill: parent
 +        source: "images/background.png"
 +    }
 +
 +    Image {
 +        id: spaceship
 +        source: "images/spaceship.png"
 +        anchors.verticalCenter: parent.verticalCenter
 +        anchors.horizontalCenter: parent.horizontalCenter
 +    }
 +}</file>
 +
 +===== Relative positioning =====
 +{{dailymotion>x11labg?small}}
 +  * **Anchors** provide a way to position an item by specifying its relationship with other items.
 +<file javascript anchors-positioners.qml>
 +import QtQuick 1.0
 +
 +Item {
 +    width: 400
 +    height: 400
 +
 +    Image {
 +        anchors.fill: parent
         source: "images/background.png"         source: "images/background.png"
     }     }
Line 13: Line 42:
     Spaceship {     Spaceship {
         id: spaceship         id: spaceship
-        x50 +        anchors.verticalCenterparent.verticalCenter 
-        y60+        anchors.horizontalCenterparent.horizontalCenter
     }     }
 }</file> }</file>
 +==== Multiple items ====
 +{{dailymotion>x11lagy?small}}
 +  * Many ways to specify how an item is related to another:
 +    * ''anchors.right'', ''anchors.rightMargin'' ...
 +<file javascript more-anchors-positioners.qml>
 +import QtQuick 1.0
 +
 +Item {
 +    width: 400
 +    height: 400
 +
 +    Image {
 +        anchors.fill: parent
 +        source: "images/background.png"
 +    }
 +
 +    Image {
 +        id: spaceship
 +        source: "images/spaceship.png"
 +        anchors.verticalCenter: parent.verticalCenter
 +        anchors.horizontalCenter: parent.horizontalCenter
 +    }
 +
 +    Image {
 +        id: anotherSpaceship
 +        source: "images/spaceship.png"
 +        scale: 0.5
 +        smooth: true
 +        anchors.top: spaceship.bottom
 +        anchors.right: spaceship.right
 +        anchors.rightMargin: 100
 +    }
 +}
 +</file>
 +
 +--------------------------------------------------------------
 +====== Resources ======
 +{{:qt-quick-for-designers-1:images.zip|}}
qt-quick-for-designers-1/positioning_elements.txt · Last modified: 2013/07/06 22:52 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki