Hi, the simplest way to achieve this is to bind the hostItem's height property to the column's height. The column's height property will change when items are added to or removed from it. This also adds some flexibility, because you don't have to know what the heights of the items in the column are (assuming that the might differ depending on the model data) - the column calculates it for you.
Juha On Sat, Sep 10, 2011 at 4:09 PM, Christian Benjamin Ries <[email protected]> wrote: > I added a "resize"-method and call this when I add elements. Is this a good > approach or does QML > support something like this native? > > [QML] > width: baseWidth; height: baseHeight; > > function resizeHost() { > hostItem.height = repeaterServices.count * 20 + baseHeight; > } > > Column { > spacing: 1; > Repeater { > id: repeaterServices; > model: modelServices; > Service { > objectName: "service" + index; > serviceName: model.modelData.name; > iconPath: model.modelData.iconPath; > textColor: model.modelData.color; > } > } > } > [/QML] > > [CPP] > QMetaObject::invokeMethod(objectHost, "resizeHost"); > [/CPP] > > Am 10/09/11 14:22, schrieb Christian Benjamin Ries: >> Brilliant, good information for my task, thanks! >> >> Currently, I have an implementation in C++ to add items to the view and I >> can use mouse-clicks. Now, >> I have one problem, how can I resize my parent item/rectangle to a fitted >> size, depending on the >> elements in my list? A screenshot is here [1]. >> >> I tried to use methods of QList, like count() to get the count of elements >> and to resize the view >> then, unfortunately count() does not exist. >> >> And in QML I use: >> [QML] >> // Area for service elements. >> Item { >> anchors.top: hostTop.bottom; >> anchors.topMargin: 10; >> x: 30; >> Column { >> spacing: 1; >> Repeater { >> model: modelServices; >> Service { >> serviceName: model.modelData.name; >> iconPath: model.modelData.iconPath; >> textColor: model.modelData.color; >> } >> } >> } >> //parent.height: modelServices.count * 20; >> } // Item >> [/QML] >> >> Suggestions? >> >> [1] http://christianbenjaminries.de/dl/_qml_/question01.png >> >> Am 10/09/11 01:09, schrieb [email protected]: >>> My first medium-sized-ish QML application was one very similar to what >>> you're proposing, and the approach worked very well. Two comments... >>> You'll want to use a C++ model to back your UI for your network resources; >>> that way you can update the model from C++ and the UI will automatically >>> redraw. You'll want to create a subclass of QAbstractListModel, or use a >>> subclass like QStandardItemModel (which is fine for general lightweight >>> work), and jam that puppy into your QML context >>> (http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#embedding-c-objects-into-qml-components, >>> http://www.lothlorien.com/kf6gpe/?p=160). Using a model is preferable to >>> using QList<T>, because as the model changes, it signals to the UI to >>> change automatically. In my case, I created a QStandardItemModel subclass >>> that was a back-end listening to QtDBus notifications, so signals on the >>> DBus propagated to, and seamlessly updated, my QML interface. It worked >>> very well. >>> >>> You can wire stuff back to your C++ app from your QML's ListView delegate >>> by using a MouseArea that dispatches to a Q_INVOKABLE property on an object >>> shared between C++ and QML; see the previous links as well. I found it >>> pretty handy (if a bit sloppy) to make my application controller class >>> available in QML, and then just put some Q_INVOKABLE methods on it so that >>> the QML could trigger state changes in the app controller logic. So your >>> app controller could have a Q_INVOKABLE method "doSomething" that the >>> MouseArea onClicked handler invokes, passing whatever info from the current >>> item of the model is necessary to your application logic. >>> >>> Hope that helps! >>> >>> Cheers, >>> R. >>> >>> >>> -----Original Message----- >>> From: [email protected] >>> [mailto:[email protected]] On Behalf Of >>> ext Christian Benjamin Ries >>> Sent: Wednesday, September 07, 2011 6:17 AM >>> To: [email protected] >>> Subject: [Qt-qml] Possibility of an implementation approach? >>> >>> Hello all together! >>> >>> I rechecherd a little bit and checked out the possibilities of QML, >>> everything sounds nice and easy to apply. I already checked how I can add >>> an QML declarative object to a GraphicScene and how I could move them >>> around. >>> >>> Now I stuck, I've no idea if I can use QML efficiently in my project. >>> >>> Here a small description of my task: >>> >>> - I have to create a graphical view of some elements, e.g. a host with >>> included childs like network-interface cards. >>> >>> - These hosts could have descriptions for file-shares, and I like to add >>> them to the host on the fly by a C++-programm, and the view sould be >>> repaint in the QGraphicalView. >>> >>> - I have seen, that I can add a list<T> in QML, could I add elements to >>> this list by C++? If yes, could you give me an example or a link to one >>> example? >>> >>> - Furthermore, when I click a one MouseArea I like to use this click-Signal >>> in my C++-programm, but there is no available example on the Qt's-website, >>> right? >>> >>> I really like to use QML, because it could safe a lot of time! Because >>> their is no need to create items of all elements with a QGraphicsItem based >>> spezialization, and the calculation of all positions and so on... >>> >>> I really checked the web and Qt's documentation, but the available examples >>> covers not really an example how I could do the mentioned implementation >>> things. >>> >>> Suggestions will be welcome(!) >>> >>> All the best, Christian >>> _______________________________________________ >>> Qt-qml mailing list >>> [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 > > -- > Dipl.-Ing. (FH) Christian Benjamin Ries, M.Sc. > University of Applied Sciences Bielefeld > Department of Engineering Sciences and Mathematics > Computational Materials Science& Engineering (CMSE) > > Wilhelm-Bertelsmann-Str. 10, D-33602 Bielefeld > Office: 202 (WBSII) > Phone: +49 521 106-71222 > Fax: +49 521 106-71241 > Web: www.christianbenjaminries.de > > _______________________________________________ > Qt-qml mailing list > [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
