ListModel only showing first item when displayed using Qt.createQmlObject
-
I am trying to dynamically create a ListModel and place it within a Rectangle. The problem is that only the first item of the List is showing up and the rest just aren't there. If I copy and paste the generated code in directly and pretend it wasn't dynamically generated but remove the imports (and the Item.. same problem if I leave the item in there!), then it works as desired. However, the generated code (as shown below after generation) requires those including the Item in order for Qt.createQmlObject to not throw an error.
Maybe I can find some other way to remove the Item which seems to be causing problems? I tried using anchors.fill in order to make sure that it isn't an issue with the size being wrong.
Please note that this generated code is being inserted within:
ApplicationWindow { ColumnLayout { Loader { Item { Rectangle { //This is the parent passed into Qt.createQmlObject
This has been bugging me for a couple days, your help/time is much appreciated!
var buttonQMLString = "import QtQuick 2.0 import QtQuick.Controls 1.5 import QtQuick.Layouts 1.3 Item { ListModel { id: buttonListModel ListElement {buttonText: \"Button1\"} ListElement {buttonText: \"Button2\"} ListElement {buttonText: \"Button3\"} ListElement {buttonText: \"Button4\"} ListElement {buttonText: \"Button5\"} } Component { id: buttonListDelegate Button { text: buttonText } } ListView { anchors.fill: parent model: buttonListModel delegate: buttonListDelegate } }"
-
Hi @mczarnek
I think you should addanchors.fill: parent
for the rootItem
which containsListModel
andListView
. So,import QtQuick.Controls 1.5 import QtQuick.Layouts 1.3 Item { anchors.fill: parent /* Note this part */ ListModel { id: buttonListModel ...
This is because this one is the actual item which is going to be a child of the item which you pass to
createQmlObject
. -
Sure, I'm new to Qt and this is one of the first features I'm trying to create, so might as well just upload the project:
http://speedy.sh/2GM4C/FractalClient.zipThere is not much else going on. I'm using the 'userdatastore' object to dynamically load the names from a file, then create the ListModel based on that.
Look in 'UserChooser.qml', the important piece is mostly in "Component.onCompleted". The commented out code is attempting to create the ListModel, then dynamically add to it. Didn't work any better than the other version.
Edit: I believe the issues is in the anchors for the bottom. Started playing with them and got them to show all buttoms... just in the wrong place.
Thank you!