[Qt-qml] Component element: what is it for ?

Sacha Zyto sacha at mit.edu
Thu Jul 22 17:44:44 CEST 2010


Hi Stephen,

My understanding is that an Item placed inside a widget will be included 
in the UI tree at that place, and hence displayed, which you don't want, 
say, if you've designed  your component to be used as a "template" or 
a"lens" in order to be used by a View to render Items that are inside a 
Model.
I hope this helps.
Best,
Sacha

Also, quoting from 
http://doc.trolltech.org/4.7-snapshot/qml-component.html:

For example, here is a component that is used by multiple Loader 
<http://doc.trolltech.org/4.7-snapshot/qml-loader.html> objects:

  Item {
      Component {
          id: redSquare

          Rectangle {
              color:"red"
              width: 10
              height: 10
          }
      }

      Loader { sourceComponent: redSquare }
      Loader { sourceComponent: redSquare; x: 20 }
  }

Notice that while a Rectangle 
<http://doc.trolltech.org/4.7-snapshot/qml-rectangle.html> by itself 
would be automatically rendered and displayed, this is not the case for 
the above rectangle because it is defined inside a Component. The 
component encapsulates the QML elements within, as if they were defined 
in a separate .qml file, and is not loaded until requested (in this 
case, by the two Loader 
<http://doc.trolltech.org/4.7-snapshot/qml-loader.html> objects).



On 07/22/2010 11:25 AM, Stephen Collyer wrote:
> Could someone explain the purpose of the Component element ?
> I can't see what it allows you to do that can't be done with an Item.
>
>    
>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100722/7ef1083d/attachment.html 


More information about the Qt-qml mailing list