سؤال

I have a listview with checkbox. I want to get the values of selected items in the list view. How can i achieve the above..?

I have posted the screenshots below :

Screen shot

This is what i have tried :

// List view declaration and its elements :

ListView {
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
                layout: FlowListLayout {
                }
                dataModel: grouplistdatamodel
                listItemComponents: [

                    ListItemComponent {
                        type: "item"
                        Container {
                            Container {
                                layout: StackLayout {
                                    orientation: LayoutOrientation.TopToBottom
                                }
                                verticalAlignment: VerticalAlignment.Center
                                horizontalAlignment: HorizontalAlignment.Center
                                preferredWidth: 768
                                Container {
                                    verticalAlignment: VerticalAlignment.Center
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.LeftToRight
                                    }
                                    CheckBox {
                                        verticalAlignment: VerticalAlignment.Center
                                    id:checkboxvalues
                                  text: ListItemData.firstname
                                   onCheckedChanged: {

                                   }


                                    }

                                }
                            }
                            Divider {
                                horizontalAlignment: HorizontalAlignment.Fill
                            }
                        }
                    }
                ]
                onTriggered: {
                _test.showToast(userid);
                }
                onCreationCompleted: {
                    group_DataSource.load();
                }
            }

Please help me to sort this out. Thanks in advance..!

لا يوجد حل صحيح

نصائح أخرى

I'm not sure about what you want to do exactly but here is how how I would store all the data checked by the user.

On onCheckedChanged :

ListView {
    ...
    listItemComponents: [
        ...
        onCheckedChanged: {
            ListItem.view.checkedDataChanged(ListItemData.firstname, checked);
        }
        ...
    ]
    function checkedDataChanged(data, isChecked) {
        controller.checkedDataChanged(data, isChecked);
    }
}
...

Where checkedDataChanged is a Q_INVOKABLE defined in the list controller's C++ class.

Then you can manage your data selected easily in a QList for instance.

Hope this helps !

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top