I would say #7: Try to reduce the amount of magic to an absolute minimum. If you have MenuItems seemingly in a Menu but really they end up in a container then you run into troubles like this. IMHO it's better to make the user type a little bit more but have it be very clear what happens. I don't know of any project that was late because developers couldn't type fast enough. :)
So my personal recommendation would be to not have a magical column but rather an explicit MenuLayout. Make the QML hierarchy reflect what really happens instead of trying to save the user from typing a few more characters. Less magic means developers understand the code better. It's a tradeoff worth making. Peppe From: "ext [email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Date: Thu, 17 Mar 2011 07:38:43 +0000 To: <[email protected]<mailto:[email protected]>> Subject: [Qt-qml] internal re-parenting of child items Hi, Is there any recommended patters how to handle internal re-parenting of child items? I’ll open up the scenario with a small example. Let’s take imaginary QML components as Menu and MenuItem (both derived from QML Item). The idea would be that the application developer would be able to write: Menu { id: optionsMenu MenuItem {…} MenuItem {…} MenuItem {…} } To populate the menu. Internally the Menu would like to use QML Column element as middle-man to layout the items as: *Menu.qml* Item { default property alias content: layout.children Column { id: layout; anchors.fill: parent } } This works like magic until someone wants to dynamically add another MenuItem: var newMenuItem = new MenuItem(optionsMenu) // wrong parent! or menuItemComponent.creatObject(optionsMenu) // wrong parent! This fails miserably and the only way this could be achieved is that the user of the Menu component would know the internal structure and would be able to write something nasty. What would be the recommended pattern? #1 never change the default property #2 never mix’n’match static and dynamic allocation of child items #3 expose middle-man as ‘container’ property which can be used in dynamic allocation #4 provide always functions to add/remove dynamic stuff #5 re-parent dynamically added children to the middle-man inside the onChildrenChanged #6 let the user do the nasty bit – they can make it work if they really want to #7 something else? Thanks, Pekka _______________________________________________ Qt-qml mailing list [email protected]<mailto:[email protected]> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
_______________________________________________ Qt-qml mailing list [email protected] http://lists.qt.nokia.com/mailman/listinfo/qt-qml
