Den 21-05-2012 13:52, Ian Geiser skrev:
>> After doing this, I think the only issue you will have is to find the
>> proper parent for your items. Things don't turn up in QML unless they
>> have a parent.
>>
> I think this is where I am stuck now.  I created my QDeclarativeItem,
> and created my root one in a VisualItemModel where and I have that
> properly showing up in the GridView.  I am really confused in the
> VisualItemModel what my parent is.  My impression is that if I could
> append the newly created QDeclarativeItem to the children property
> that I would be okay.  But like you said finding the proper parent is
> the key issue here.  At the end of the day I can get one of the items
> into the UI, but where I get killed is when the bound
> QDeclarativeItem creates a new QDeclarativeItem that is to be added
> to the same container that the original one is in.

Just to be sure: You did call setParentItem, right?

I know you have worked with Qt for years, so I'm not trying to be 
condescending. But we all sometimes miss the obvious :)

In QML, parents don't work exactly like in Qt. The differences are 
subtle, but they are there. For example, unless you set clipping to 
true, children can paint anywhere in the window, regardless of how big 
the parent is.

You need the items to have an item for the parent, you need the size and 
position, and you need the painting of them. And of course that the 
parent is visible. If that's the case, you should see the children. I 
just checked some of the code I have that dynamically adds items to an 
existing scene, and there is nothing more to it than this.

One thing that I have learned to do, though, is to take QML in very 
small steps. For your kind of project, I would do something like

1) get the parent showing
2) implement a very simple item (a filled square for example)
3) add this to the parent

Once this works, then you can start replacing the square with your own code.

Sounds really trivial, but when I'm doing widget based Qt code, I do 
much much larger steps each time. The reason for this is that QML is 
*so* hard to debug. So unless you know exactly which step failed, it's 
incredibly difficult to find out which area of the code has the problem.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
_______________________________________________
Qt-qml mailing list
Qt-qml@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to