<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>QtQuick Examples</title>
	<atom:link href="http://jryannel.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jryannel.wordpress.com</link>
	<description>A quick look on QML</description>
	<lastBuildDate>Fri, 05 Mar 2010 05:00:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jryannel.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/3149eeb61042b55f7ea5bec946b57928?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>QtQuick Examples</title>
		<link>http://jryannel.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jryannel.wordpress.com/osd.xml" title="QtQuick Examples" />
	<atom:link rel='hub' href='http://jryannel.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Moving a ToolBar in</title>
		<link>http://jryannel.wordpress.com/2010/03/05/moving-a-toolbar-in/</link>
		<comments>http://jryannel.wordpress.com/2010/03/05/moving-a-toolbar-in/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 05:00:36 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=289</guid>
		<description><![CDATA[In this example I will move a toolbar into the main rectangle. The toolbar get&#8217;s hidden when the user clicks outside the toolbar. We create an outer rectangle our &#8220;screen&#8221; and an inner rectangle which is initially hidden and located outside the bottom of the screen (y:200). Both rectangles have a mouse region attached, to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=289&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this example I will move a toolbar into the main rectangle. The toolbar get&#8217;s hidden when the user clicks outside the toolbar.<br />
<span id="more-289"></span></p>
<p>We create an outer rectangle our &#8220;screen&#8221; and an inner rectangle which is initially hidden and located outside the bottom of the screen (y:200). Both rectangles have a mouse region attached, to control user interaction.</p>
<p>So when we start it, the screen looks like a black panel.</p>
<p><a href="http://jryannel.files.wordpress.com/2010/03/snapshot1.png"><img src="http://jryannel.files.wordpress.com/2010/03/snapshot1.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-316" /></a></p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
    width: 200
    height: 200
    color: &quot;black&quot;
    property bool on: false

    MouseRegion { id: region; anchors.fill: parent; onClicked: toolbar.toggle()}

    Rectangle {
      id: toolbar
      color: &quot;gray&quot;
      x: 20; y: 200;
      width: 160; height: 48
      opacity: 0
      function toggle() {
        on = on==true?false:true
      }
      states : State {
        name: &quot;shown&quot;
        when: on
        PropertyChanges{target:toolbar; y: 150; opacity: 1}
      }
      transitions: [
        Transition {
          NumberAnimation { matchProperties: &quot;y,opacity&quot;; duration: 500 }
        }
      ]
      MouseRegion { anchors.fill: parent; onClicked: console.log(&quot;toolbar clicked&quot;)}
    }
}
</pre>
<p>When the user clicks on the MouseRegion <code>region</code> the toolbar is toggled and the <code>on property</code> is changed. A change in the on property will result into a state change, which contains the properties for a visible toolbar (y, opacity). The state transition is animated via a NumberAnimation.</p>
<p>The screen with visible toolbar looks like this:<br />
<a href="http://jryannel.files.wordpress.com/2010/03/snapshot2.png"><img src="http://jryannel.files.wordpress.com/2010/03/snapshot2.png?w=200&#038;h=200" alt="" title="snapshot2" width="200" height="200" class="alignnone size-full wp-image-317" /></a></p>
<p>Another click on the MouseRegion <code>region</code> will hide the toolbar again.</p>
<p><em>Note</em>: It&#8217;s important to have the larger mouse region first. Siblings declared later in a QML file are considered to be on top of those declared earlier. <strong>So order of declaration is important!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=289&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/03/05/moving-a-toolbar-in/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/03/snapshot1.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/03/snapshot2.png" medium="image">
			<media:title type="html">snapshot2</media:title>
		</media:content>
	</item>
		<item>
		<title>Like-O-Meter</title>
		<link>http://jryannel.wordpress.com/2010/03/01/like-o-meter/</link>
		<comments>http://jryannel.wordpress.com/2010/03/01/like-o-meter/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 05:00:10 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=263</guid>
		<description><![CDATA[A like-o-meter is used when a user shall rate content. In this case it&#8217;s a series of stars a user can give. This time we begin with the desired output. Here is the a screenshot of the final example: Defining the Star We begin to sketch our star in a Star.qml file. import Qt 4.6 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=263&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A like-o-meter is used when a user shall rate content. In this case it&#8217;s a series of stars a user can give.<br />
<span id="more-263"></span></p>
<p>This time we begin with the desired output. Here is the a screenshot of the final example:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot16.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot16.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-264" /></a></p>
<p><strong>Defining the Star</strong></p>
<p>We begin to sketch our star in a Star.qml file.</p>
<pre class="brush: css;">
import Qt 4.6

Item {
  id: container
  width: 24
  height: 24

  property int rating
  property bool on
  signal clicked

  Image {
    id: starImage
    source: &quot;images/star.png&quot;
    x: 6
    y: 7
    opacity: 0.4
    scale: 0.5
  }
  MouseRegion {
    anchors.fill: container
    onClicked: { container.clicked() }
  }
  states: [
  State {
    name: &quot;on&quot;
    when: container.on == true
    PropertyChanges {
      target: starImage
      opacity: 1
      scale: 1
      x: 1
      y: 0
    }
  }
  ]
  transitions: [
  Transition {
    NumberAnimation {
      matchProperties: &quot;opacity,scale,x,y&quot;
      easing: &quot;easeOutBounce&quot;
    }
  }
  ]
}
</pre>
<p>The star.png image looks like this:<br />
<a href="http://jryannel.files.wordpress.com/2010/02/star.png"><img src="http://jryannel.files.wordpress.com/2010/02/star.png?w=22&#038;h=24" alt="" title="star" width="22" height="24" class="alignnone size-full wp-image-265" /></a></p>
<p>The Star.qml component consist mainly of an Image element, the star.png file, which is displayed at 50% scale and 40% opacity.</p>
<p>The star changes when the <code>property on</code> is set to <code>true</code>. This is controlled by the <code>state "on"</code>. It changes the opacity to 100% and scale to 100%, additional the position is adjusted. A transition makes the state switch smooth.</p>
<p><strong>Using the Star</strong></p>
<p>The Star.qml component is used inside the LikeOMeter.qml file.</p>
<pre class="brush: css;">
import Qt 4.6

Item {
  id: container

  property int rating: 2

  Row {
    Star {
      rating: 0
      onClicked: { container.rating = rating }
      on: container.rating &gt;= 0
    }
    Star {
      rating: 1
      onClicked: { container.rating = rating }
      on: container.rating &gt;= 1
    }
    Star {
      rating: 2
      onClicked: { container.rating = rating }
      on: container.rating &gt;= 2
    }
    Star {
      rating: 3
      onClicked: { container.rating = rating }
      on: container.rating &gt;= 3
    }
    Star {
      rating: 4
      onClicked: { container.rating = rating }
      on: container.rating &gt;= 4
    }
  }
}
</pre>
<p>The LikeOMeter consist of a row of stars. Each star&#8217;s <code>on property</code> is set when the rating hits a specific threshold, which then results into painting the star image at 100% scale and 100% opacity based on the star <code>"on" state</code>.</p>
<p>When the star&#8217;s mouse region is pressed the clicked signal is emitted and handled in the onClicked handler, in this case it&#8217;s updates the container rating property. Which is bound by the threshold to the <code>on property</code> of the star again. So s<code>tar clicked</code> leads to <code>container rating</code> changes, leads to <code>property on</code> evaluation, can lead to <code>star "on"</code> state. Nice chain!</p>
<p><strong>Using the LikeOMeter</strong></p>
<p>You would use the LikeOMeter similar like this:</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
  id: container
  width: 200
  height: 200
  Column {
    anchors.centerIn: parent;
    spacing: 16
    LikeOMeter {
      id: likeOMeter
      width: 150; height: 30
    }
    Text { text: &quot;Rating: &quot; +likeOMeter.rating }
  }
}
</pre>
<p>The Text is updated, when the rating changes. The rating changes, when a star is clicked. Sweet!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/263/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=263&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/03/01/like-o-meter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot16.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/star.png" medium="image">
			<media:title type="html">star</media:title>
		</media:content>
	</item>
		<item>
		<title>Displaying an Image with a scroll indicator</title>
		<link>http://jryannel.wordpress.com/2010/02/26/displaying-an-image-with-a-scroll-indicator/</link>
		<comments>http://jryannel.wordpress.com/2010/02/26/displaying-an-image-with-a-scroll-indicator/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 05:00:29 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=248</guid>
		<description><![CDATA[An Image element displayed in a Flickable element can be scrolled in the Flickable&#8217;s viewport. To indicate the position the user is currently looking at we will develop a simple scroll indicator. First of all: &#8220;What is a Flickable element?&#8221;. It&#8217;s an element, which surface can be flipped. This is similar like a scroll area. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=248&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An Image element displayed in a Flickable element can be scrolled in the Flickable&#8217;s viewport. To indicate the position the user is currently looking at we will develop a simple scroll indicator.<br />
<span id="more-248"></span></p>
<p>First of all: &#8220;What is a Flickable element?&#8221;. It&#8217;s an element, which surface can be flipped. This is similar like a scroll area. You display content, which is bigger then the element itself. The viewport than shows the content only partially. To move the viewport you can flip the surface.</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
  id: container
  width: 200; height: 200;
  Flickable {
    id: flickable
    anchors.fill: parent;
    viewportWidth: image.width; viewportHeight: image.height
    Image { id: image; source: &quot;qt_architecture.png&quot; }
  }
  // extension
}
</pre>
<p>The image can be any bigger image, which is available. This will give you an image viewer, where you can flip the image in the desired direction.<br />
<a href="http://jryannel.files.wordpress.com/2010/02/snapshot17.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot17.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-272" /></a></p>
<p>This is already pretty cool. What you would like to have additional is an indicator, which area of the image you are currently looking at: A scroll bar.</p>
<p><strong>The Scrollbar</strong></p>
<pre class="brush: css;">
import Qt 4.6

Rectangle { // background
    id: container
    color: white;

    property var flickableArea

    Rectangle { // viewport indicator
      y: flickableArea.visibleArea.yPosition * container.height
      width: parent.width
      height: flickableArea.visibleArea.heightRatio * container.height
        color: &quot;black&quot;
        opacity: 0.7
    }
</pre>
<p>The scroll bar in this case is a white rectangle which will be painted on the right of the visible image area later. The white-rectangle has an inner rectangle which indicates the current visible area.</p>
<p><strong>Using the Scrollbar</strong></p>
<p>We append to our previous flickable code where &#8220;extension&#8221; is marked the following:</p>
<pre class="brush: css;">
  ScrollBar {
    id: scrollBar
    anchors.right: flickable.right; y: flickable.y
    width: 8; height: flickable.height
    flickableArea: flickable
  }
</pre>
<p>This adds the scrollbar to the right edge of the flickable with a width of 8 along the whole height.</p>
<p>The result will look like this:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot18.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot18.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-273" /></a></p>
<p>Please note the right scroll indicator.</p>
<p><strong>Polishing</strong></p>
<p>When you add these 2 lines </p>
<pre class="brush: css;">
    opacity: flickableArea.moving? .7 : 0;
    opacity: Behavior { NumberAnimation { duration: 400 } }
</pre>
<p>to the scrollbar component file, it will make the scrollbar invisible if the image is resting and make the scroll indicator to appear smooth. Please note that the 1st opacity statement gives the default value and the 2nd the behavior.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=248&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/26/displaying-an-image-with-a-scroll-indicator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot17.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot18.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the ListView with an XML Model</title>
		<link>http://jryannel.wordpress.com/2010/02/24/using-the-listview-with-an-xml-model/</link>
		<comments>http://jryannel.wordpress.com/2010/02/24/using-the-listview-with-an-xml-model/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 05:00:18 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=243</guid>
		<description><![CDATA[The ListView can also be used with more advanced models, like the XmlListModel. The XmlListModel allows you to specify a XPath query to extract information from the XML data source. We will use flickr&#8217;s feed services as a data source. This is how the final list of flickr thumbnails will look like. First we investigate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=243&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The ListView can also be used with more advanced models, like the <a href="http://qt.nokia.com/doc/qml-snapshot/qml-xmllistmodel.html">XmlListModel</a>. The XmlListModel allows you to specify a XPath query to extract information from the XML data source.<br />
<span id="more-243"></span></p>
<p>We will use <a href="http://www.flickr.com/services/feeds/">flickr&#8217;s feed services</a> as a data source. </p>
<p>This is how the final list of flickr thumbnails will look like.<br />
<a href="http://jryannel.files.wordpress.com/2010/02/snapshot110.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot110.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-297" /></a></p>
<p>First we investigate into the format used. A simple call to curl will provide us the http response.</p>
<pre class="brush: plain;">
curl http://api.flickr.com/services/feeds/photos_public.gne?format=rss2
</pre>
<p>You could also just point your browser to that url. The response looks similar to this (simplified):</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;rss&gt;
    &lt;channel&gt;
        &lt;item&gt;
            &lt;title&gt;Maringá 123&lt;/title&gt;
            &lt;media:thumbnail url=&quot;http://farm5.static.flickr.com/4052/4362801819_e2f46d6306_s.jpg&quot; height=&quot;75&quot; width=&quot;75&quot;/&gt;
        &lt;/item&gt;
        &lt;item&gt;
            &lt;media:thumbnail url=&quot;http://farm5.static.flickr.com/4048/4362801851_b80289ca0e_s.jpg&quot; height=&quot;75&quot; width=&quot;75&quot;/&gt;
</pre>
<p>We are mostly interested in the url attribute of the media:thumbnail tag to display later the thumbnail in our delegate.</p>
<p>To catch the url we use an <a href="http://www.w3schools.com/XPath/default.asp">xpath</a> expression: <code>/rss/channel/item</code>. This gives us the list of items in the feed.</p>
<p>To access the url attribute we use in a further step a second selector: <code>media:thumbnail/@url</code>. This gives us the desired url, which we can feed to our delegate.</p>
<p>There is still one roadblock left. We use the xml namespace <code>media:</code>. To make the namespace available we will add it to the XmlListModel later.</p>
<p>Here now the code:</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
  width: 200
  height: 200

  Component {
    id: delegate
    Image {
      source: thumbnail
    }
  }

  ListView {
    id: view
    anchors.fill: parent
    model: model
    delegate: delegate
  }
  XmlListModel {
    id: model
    namespaceDeclarations: &quot;declare namespace media=\&quot;http://search.yahoo.com/mrss/\&quot;;&quot;
    source: &quot;http://api.flickr.com/services/feeds/photos_public.gne?format=rss2&quot;
    query: &quot;/rss/channel/item&quot;
    XmlRole { name: &quot;thumbnail&quot;; query: 'media:thumbnail/@url/string()' }
  }

}
</pre>
<p>The most interesting part is the XmlListModel. First we make the xml namespace available to the XmlListModel and then we add the query, which provides us a list of <code>item</code> elements. N</p>
<p>The XmlRole extracts information per item, in this case the thumbnail url attribute, which is converted into a string with <code>string()</code>.</p>
<p>We use the thumbnail role now in our delegate to load an image from this url. We have not set a size on the image. It will take in this case the loaded image size.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/243/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=243&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/24/using-the-listview-with-an-xml-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot110.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the ListView with a model</title>
		<link>http://jryannel.wordpress.com/2010/02/23/using-the-listview-with-a-model/</link>
		<comments>http://jryannel.wordpress.com/2010/02/23/using-the-listview-with-a-model/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 05:00:12 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=241</guid>
		<description><![CDATA[This post explains shortly how to use a ListView with a simple model and a delegate to paint the model data. To display a content in a ListView you need a model (e.g. ListModel) and a delegate (a Component). The model contains the data to be displayed, the delegate knows how to paint each model [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=241&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post explains shortly how to use a <a href="http://qt.nokia.com/doc/qml-snapshot/qml-listview.html">ListView</a> with a simple model and a delegate to paint the model data.<br />
<span id="more-241"></span></p>
<p>To display a content in a ListView you need a model (e.g. <a href="http://qt.nokia.com/doc/qml-snapshot/qml-listmodel.html">ListModel</a>) and a delegate (a Component).<br />
The model contains the data to be displayed, the delegate knows how to paint each model element.<br />
The ListView provides a flickable area, which lays out the elements in a vertical line.</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
  width: 200; height: 200

  Component {
    id: delegate
    Item {
      width: 200; height: 28
      Text {
        text: title
      }
    }
  }

  ListView {
    anchors.fill: parent
    model: model
    delegate: delegate
  }

  ListModel {
    id: model
    ListElement { title: &quot;Germany&quot; }
    ListElement { title: &quot;France&quot; }
    ListElement { title: &quot;Italy&quot; }
    ListElement { title: &quot;United Kingdom&quot; }
  }
}
</pre>
<p>The ListView can also have a horizontal orientation or a highlighter component. The delegate is bound to the model by the model element names (here <code>title</code>).</p>
<p>Besides the ListModel there is also a XmlListModel and a VisualItemModel. The XmlListModel get&#8217;s the data from an Xml content (e.g. RSS feed) and selects the right parts based on a XPath query. The VisualItemModel contains data and delegate. A good coverage of model data can be found <a href="http://qt.nokia.com/doc/qml-snapshot/qmlmodels.html#qmlmodels">here</a>.</p>
<p>Here a more complex example:</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
  id: container
  width: 200; height: 200
  Component {
    id: delegate
    Item {
      width: 200; height: 28
      Text {
        x: 8
        text: title
        anchors.verticalCenter: parent.verticalCenter
      }
      Rectangle {
        height: 12; width: population;
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter
        color: &quot;lightsteelblue&quot;
      }
    }

  }

  ListView {
    id: view
    anchors.fill: parent
    model: model
    delegate: delegate
  }

  ListModel {
    id: model
    ListElement {
      title: &quot;Germany&quot;
      population: 81
    }
    ListElement {
      title: &quot;France&quot;
      population: 65
    }
    ListElement {
      title: &quot;Italy&quot;
      population: 60
    }
    ListElement {
      title: &quot;United Kingdom&quot;
      population: 62
    }
  }
}
</pre>
<p>The delegate now display a horizontal bar, based on the <code>population</code> of the country.</p>
<p>Here the screenshot to the example:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot19.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot19.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-291" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/241/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=241&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/23/using-the-listview-with-a-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot19.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
		<item>
		<title>Designing a Login View</title>
		<link>http://jryannel.wordpress.com/2010/02/22/designing-a-login-view/</link>
		<comments>http://jryannel.wordpress.com/2010/02/22/designing-a-login-view/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 05:00:48 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=225</guid>
		<description><![CDATA[Now we have all building blocks together to create a login view with username and password field and 2 buttons, one for login the other one for login as guest. The source code of this example called ex1 is now available from my qml-posts repository at gitorious.org This is a sketch I made for the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=225&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now we have all building blocks together to create a login view with username and password field and 2 buttons, one for login the other one for login as guest.<br />
<span id="more-225"></span></p>
<blockquote><p>The source code of this example called <strong>ex1</strong> is now available from my <a href="http://gitorious.org/qml-posts">qml-posts repository at gitorious.org</a></p></blockquote>
<p>This is a sketch I made for the login view. </p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/loging_sketch.png"><img src="http://jryannel.files.wordpress.com/2010/02/loging_sketch.png?w=232&#038;h=268" alt="" title="loging_sketch" width="232" height="268" class="alignnone size-full wp-image-226" /></a></p>
<p>As you can see the structuring is made up of nested Row and Column elements.</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
  width: 640
  height: 480
  Background { anchors.fill: parent }
  Column {
    anchors.centerIn: parent
    spacing: 16
    Column {
      spacing: 4
      MediumText { text: &quot;Username&quot; }
      LineInput { focus: true }
    }
    Column {
      spacing: 4
      MediumText { text: &quot;Password&quot; }
      LineInput { input.echoMode: TextInput.Password }
    }
    Row {
      spacing: 16
      anchors.horizontalCenter: parent.horizontalCenter
      Button { text: &quot;Login&quot;; onClicked: console.log(&quot;login&quot;) }
      Button { text: &quot;Guest&quot;; onClicked: console.log(&quot;guest&quot;) }
    }
  }
}
</pre>
<ul>
<li>MediumText is just a Text element with predefined formatting, so I don&#8217;t have to repeat is in the code. </li>
<li>The LineInput is a TextInput wrapped with a BorderImage for pleasure.</li>
<li>The background is a small image tiled over the parents area.</li>
</ul>
<p>These components where discussed in earlier posts.</p>
<p>Here the screenshot of the result:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot21.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot21.png?w=276&#038;h=328" alt="" title="snapshot2" width="276" height="328" class="alignnone size-full wp-image-239" /></a></p>
<p><em>What currently is not working is the KeyNavigation. For example in the user name text input element, pressing down should move the focus to the password input. QML is in general supporting this with the KeyNavigation attached property. The problem i&#8217;m facing is only how I defined the reusable LineInput component, does not allow me to access the attached property KeyNavigation of the text input.</em></p>
<p>If you know a workaround, please let me know. Thanks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=225&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/22/designing-a-login-view/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/loging_sketch.png" medium="image">
			<media:title type="html">loging_sketch</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot21.png" medium="image">
			<media:title type="html">snapshot2</media:title>
		</media:content>
	</item>
		<item>
		<title>Rows and Columns</title>
		<link>http://jryannel.wordpress.com/2010/02/19/rows-and-columns/</link>
		<comments>http://jryannel.wordpress.com/2010/02/19/rows-and-columns/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 05:00:07 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=210</guid>
		<description><![CDATA[The Row/Column element in QML are called positioners. They position their children horizontally/vertically in a line-up. The Column and Row elements have the same properties: spacing, add and move. Spacing defines the space between positioned elements and add/move defines transitions when an element is added or moved (removed). First a simple example using Row and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=210&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://qt.nokia.com/doc/qml-snapshot/qml-row.html">Row</a>/<a href="http://qt.nokia.com/doc/qml-snapshot/qml-column.html">Column</a> element in QML are called positioners. They position their children horizontally/vertically in a line-up.<br />
<span id="more-210"></span></p>
<p>The Column and Row elements have the same properties: <code>spacing</code>, <code>add</code> and <code>move</code>. Spacing defines the space between positioned elements and add/move defines transitions when an element is added or moved (removed).</p>
<p>First a simple example using Row and Column. You need to take care that the Row and Column element can determine the size of the elements. </p>
<p><strong>Note: </strong><em>In my first try I tried to set the Rectangles width based on the Columns width, which resulted in 0 width. As no element had any real width defined.</em> </p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
    width: 200
    height: 200

    Column { /* outer column */
      spacing: 10
      Text { text: &quot;Column Element&quot;}
      Column { /* inner column */
        x: 10; y: 10
        spacing: 10
        Rectangle { width: 40; height: 20; color: &quot;red&quot; }
        Rectangle { width: 40; height: 20; color: &quot;green&quot; }
        Rectangle { width: 40; height: 20; color: &quot;blue&quot; }
      }
      Text { text: &quot;Row Element&quot; }
      Row { /* inner row */
        spacing: 10
        Rectangle { width: 40; height: 20; color: &quot;red&quot; }
        Rectangle { width: 40; height: 20; color: &quot;green&quot; }
        Rectangle { width: 40; height: 20; color: &quot;blue&quot; }
      }
    }
}
</pre>
<p>The result looks like this:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot14.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot14.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-212" /></a></p>
<p><strong>Dynamic Positioners</strong></p>
<p>For trying out a dynamic aspect, I added a mouse region, which cover the whole scene. When pressed two selected rectangles will get invisible. To animate the whole process I added a <a href="http://qt.nokia.com/doc/qml-snapshot/qml-numberanimation.html">number animation</a> to the move property to the outer column. As this is a Column, only &#8216;y&#8217; as a matching property is interesting to us.</p>
<pre class="brush: css;">
import Qt 4.6

Rectangle {
    width: 200
    height: 200

    Column {
      spacing: 10
      move: Transition {
               NumberAnimation {
                   matchProperties: &quot;y&quot;
                   easing: &quot;easeLinear&quot;
                   duration: 500
               }
           }
      Text { text: &quot;Column Element&quot;}
      Column {
        x: 10; y: 10
        spacing: 10
        Rectangle { width: 40; height: 20; color: &quot;green&quot; }
        Rectangle {
          width: 40; height: 20; color: &quot;red&quot;
          opacity: region.pressed? 0 : 1
        }
        Rectangle { width: 40; height: 20; color: &quot;blue&quot; }
      }
      Text { text: &quot;Row Element&quot; }
      Row {
        spacing: 10
        Rectangle { width: 40; height: 20; color: &quot;green&quot; }
        Rectangle {
          width: 40; height: 20; color: &quot;red&quot;;
          opacity: region.pressed? 0 : 1
        }
        Rectangle { width: 40; height: 20; color: &quot;blue&quot; }
      }
    }
    MouseRegion {
      id: region
      anchors.fill: parent
    }
}
</pre>
<p>What happens now is that when you press the mouse region, two rectangles will change to invisible. The column will update it&#8217;s size and reposition the remaining rectangles. The repositioning is animated via the number animation. Please have a try and see for yourself.</p>
<p>If you ever wondered which easing curves are available. They are documented <a href="http://qt.nokia.com/doc/qml-snapshot/qml-propertyanimation.html#easing-prop">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=210&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/19/rows-and-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot14.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
		<item>
		<title>A TextInput Component</title>
		<link>http://jryannel.wordpress.com/2010/02/18/a-textinput-component/</link>
		<comments>http://jryannel.wordpress.com/2010/02/18/a-textinput-component/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 05:00:59 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=199</guid>
		<description><![CDATA[In a previous post we post, we developed a beautiful TextInput with borders. In this post, we will extract this in a component for later reuse. The previus developed TextInput scene looked like this: import Qt 4.6 Item { width: 200 height: 200 Background { id: background } Item { property alias text: input.text anchors.centerIn: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=199&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a previous post we post, we developed a beautiful TextInput with borders. In this post, we will extract this in a component for later reuse.<br />
<span id="more-199"></span></p>
<p>The previus developed TextInput scene looked like this:</p>
<pre class="brush: css;">
import Qt 4.6

Item {
    width: 200
    height: 200

    Background { id: background }
    Item {
        property alias text: input.text
        anchors.centerIn: parent
        width: 180; height: 28
        BorderImage {
            source: &quot;images/lineedit.sci&quot;
            anchors.fill: parent
        }
        TextInput {
            id: input
            color: &quot;#151515&quot;; selectionColor: &quot;green&quot;
            font.pixelSize: 16; font.bold: true
            width: parent.width-16
            maximumLength: 16
            anchors.centerIn: parent
            focus: true
        }
    }
}
</pre>
<p>To be able to extract a text input component we create a new file called <code>LineInput.qml</code>. And extract the relevant parts.</p>
<pre class="brush: css;">
import Qt 4.6

Item {
    property alias text: input.text
    property alias maximumLength: input.maximumLength
    anchors.centerIn: parent
    width: 180; height: 28
    BorderImage {
        source: &quot;images/lineedit.sci&quot;
        anchors.fill: parent
    }
    TextInput {
        id: input
        color: &quot;#151515&quot;; selectionColor: &quot;green&quot;
        font.pixelSize: 16; font.bold: true
        width: parent.width-16
        anchors.centerIn: parent
        focus: true
    }
}
</pre>
<p>I added an alias to the maximum length for convenience. The calling code changes now to:</p>
<pre class="brush: css;">
LineInput {
    anchors.centerIn: parent
    width: 140
    text: &quot;My LineEdit&quot;
}
</pre>
<p>What happens now is the TextInput does not get focus for editing. My first attempt was to add just <code>focus: true</code> to the LineInput. But this didn&#8217;t solve the problem. Also the LineInput received the focus, its not forwarded to the inner text input.<br />
My second attempt was to add an alias for focus on the LineInput to forward the focus. This resulted in a </p>
<blockquote><p>Cannot override FINAL property &#8216;property alias focus: true&#8217;</p></blockquote>
<p> message. What now?</p>
<p><strong>FocusScope</strong> to the rescue.</p>
<p>A <a href="http://qt.nokia.com/doc/qml-snapshot/qmlfocus.html">FocusScope</a> defines a boundary for focus. If one child-element has set <code>focus: true</code> and the focus scope will receive focus it will forward the focus to that element.</p>
<p>You can read more about focus handling in QML <a href="http://qt.nokia.com/doc/qml-snapshot/qmlfocus.html">here</a>.</p>
<p>So we change our Item in <code>LineInput.qml</code> to a FocusScope:</p>
<pre class="brush: css;">
import Qt 4.6

FocusScope {
    property alias text: input.text
    property alias maximumLength: input.maximumLength
    anchors.centerIn: parent
    width: 180; height: 28
    BorderImage {
        source: &quot;images/lineedit.sci&quot;
        anchors.fill: parent
    }
    TextInput {
        id: input
        color: &quot;#151515&quot;; selectionColor: &quot;green&quot;
        font.pixelSize: 16; font.bold: true
        width: parent.width-16
        anchors.centerIn: parent
        focus: true
    }
}
</pre>
<p>And the calling code to:</p>
<pre class="brush: css;">
LineInput {
    anchors.centerIn: parent
    width: 140
    text: &quot;My LineEdit&quot;
    focus: true
}
</pre>
<p>The focus is now forwarded into the focus requesting element inside the scope. Sweet.</p>
<p><strong>Exposing the TextInput</strong></p>
<p>While I aliased some properties of the TextInput in the component for easier access it is also possible to expose the TextInput itself. Just use</p>
<pre class="brush: css;">
property alias input: input
</pre>
<p>in <code>LineInput.qml</code> and now you can access the TextInput like this:</p>
<pre class="brush: css;">
LineInput {
    anchors.centerIn: parent
    width: 140
    focus: true
    input.text: &quot;No Way&quot;
}
</pre>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot13.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot13.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-205" /></a></p>
<p>Another sweet thing <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Take care!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=199&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/18/a-textinput-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot13.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
		<item>
		<title>DIGIA demos Qt Quick</title>
		<link>http://jryannel.wordpress.com/2010/02/17/digia-demos-qt-quick/</link>
		<comments>http://jryannel.wordpress.com/2010/02/17/digia-demos-qt-quick/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 07:37:37 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=323</guid>
		<description><![CDATA[If you ever wondered, what is possible with QtQuick, aka QML have a look. Sweet!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=323&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you ever wondered, what is possible with QtQuick, aka QML have a look.</p>
<span style="text-align:center; display: block;"><a href="http://jryannel.wordpress.com/2010/02/17/digia-demos-qt-quick/"><img src="http://img.youtube.com/vi/0NK4zeAe5-Y/2.jpg" alt="" /></a></span>
<p>Sweet!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/323/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/323/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=323&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/17/digia-demos-qt-quick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>
	</item>
		<item>
		<title>Using TextInput</title>
		<link>http://jryannel.wordpress.com/2010/02/17/using-textinput/</link>
		<comments>http://jryannel.wordpress.com/2010/02/17/using-textinput/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 05:00:09 +0000</pubDate>
		<dc:creator>jryannel</dc:creator>
				<category><![CDATA[QML]]></category>

		<guid isPermaLink="false">http://jryannel.wordpress.com/?p=185</guid>
		<description><![CDATA[TextInput allows you to add an editable line to your scene. A simple TextInput has no real visual background representation. It only presents a cursor indicator and the text to be displayed. The color property defines the text color and the focus property set on true request focus for this element. import Qt 4.6 Item [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=185&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://qt.nokia.com/doc/qml-snapshot/qml-textinput.html">TextInput</a> allows you to add an editable line to your scene.</p>
<p><span id="more-185"></span></p>
<p>A simple TextInput has no real visual background representation. It only presents a cursor indicator and the text to be displayed. The color property defines the text color and the focus property set on true request focus for this element.</p>
<pre class="brush: css;">
import Qt 4.6

Item {
    width: 200
    height: 200

    TextInput {
        id: input
        color: &quot;red&quot;
        text: &quot;Default Text&quot;
        width: parent.width-16; height: 28
        anchors.centerIn: parent
        focus: true
    }
}
</pre>
<p>The not so good looking example looks like this:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot2.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot2.png?w=200&#038;h=200" alt="" title="snapshot2" width="200" height="200" class="alignnone size-full wp-image-191" /></a></p>
<p>As you can see, its difficult to identify the TextInputs borders. So in the next step we will add a border on the TextInput.</p>
<p><strong>Beautifying</strong></p>
<p>To beautify the scene, we first apply our Background component, developed in an earlier post.<br />
Then we wrap our TextInput in an Item together with a BorderImage, which will provide a more accurate presentation.</p>
<p>The <code>lineedit.sci</code> is defined as this:</p>
<pre class="brush: css;">
border.left: 10
border.top: 10
border.bottom: 10
border.right: 10
source: lineedit.png
</pre>
<p>and the <code>lineedit.png</code> looks like this:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/lineedit.png"><img src="http://jryannel.files.wordpress.com/2010/02/lineedit.png?w=44&#038;h=38" alt="" title="lineedit" width="44" height="38" class="alignnone size-full wp-image-186" /></a></p>
<p>They define the border of our TextInput. To make it easier to access the TextInput text property we define an alias on the Item level, which references the TextInput&#8217;s text property.</p>
<pre class="brush: css;">
import Qt 4.6

Item {
    width: 200
    height: 200

    Background { id: background }
    Item {
        property alias text: input.text
        anchors.centerIn: parent
        width: 180; height: 28
        BorderImage {
            source: &quot;images/lineedit.sci&quot;
            anchors.fill: parent
        }
        TextInput {
            id: input
            color: &quot;#151515&quot;; selectionColor: &quot;green&quot;
            font.pixelSize: 16; font.bold: true
            width: parent.width-16
            maximumLength: 16
            anchors.centerIn: parent
            focus: true
        }
    }
}
</pre>
<p>The result will look like this:</p>
<p><a href="http://jryannel.files.wordpress.com/2010/02/snapshot12.png"><img src="http://jryannel.files.wordpress.com/2010/02/snapshot12.png?w=200&#038;h=200" alt="" title="snapshot1" width="200" height="200" class="alignnone size-full wp-image-195" /></a></p>
<p>And looks already much more appealing. As the TextInput is just a QML element it can also take part in any kind of animations and transitions. </p>
<p>Additional TextInput allows you to set an input mask and validators and redefine the cursor displayed.</p>
<p>Also in this example we could extract a component. This is handled in a following post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jryannel.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jryannel.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jryannel.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jryannel.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jryannel.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jryannel.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jryannel.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jryannel.wordpress.com/185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jryannel.wordpress.com&amp;blog=11895070&amp;post=185&amp;subd=jryannel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jryannel.wordpress.com/2010/02/17/using-textinput/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b55262ca63f385865d0504e1a0095aa8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jryannel</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot2.png" medium="image">
			<media:title type="html">snapshot2</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/lineedit.png" medium="image">
			<media:title type="html">lineedit</media:title>
		</media:content>

		<media:content url="http://jryannel.files.wordpress.com/2010/02/snapshot12.png" medium="image">
			<media:title type="html">snapshot1</media:title>
		</media:content>
	</item>
	</channel>
</rss>
