Search code examples
qtcomboboxqmltableview

QML and comboBox inside TableView


I'm trying to design a mobile application with comboBox inside TableView.

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.2
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6
import QtQuick.Controls.Styles 1.2

ApplicationWindow {

    visible: true
    width: 640
    height: 480
    title: qsTr("Scroll")

    Component.onCompleted: {
        var i=0;
        for(;i<50;i++)
        {
            console.log("ApplicationWindow.onCompleted");

            var myBoject = {"text":"Banana"};
            idListModelForFlightToExport.append(myBoject);
        }

    }

    ListModel {
        id: idListModelForFlightToExport
    }

    Component  {
        id: checkBoxDelegate
        ComboBox {
            anchors.fill: parent;
            model: [ {"text":"Banana"}, {"text":"Apple"}, {"text":"Coconut"} ]
            textRole: "text";
            Component.onCompleted: {
                console.log("checkBoxDelegate.onCompleted");
            }
        }
    }

    TableView {
        id: idTableViewFlightsToExport

        sortIndicatorVisible: false

        model: idListModelForFlightToExport
        anchors.fill: parent
        TableViewColumn {
            id: isExportedColumn
            title: qsTr("Column")
            movable: false
            resizable: false
            delegate:checkBoxDelegate
        }
    }
}

But when I change the value of a comboBox, and then I scroll down, some others comboBox change their value.

i.e if I change the first combo, and I scroll, the value of the first combo will be display on another combo (which seems randomly choosen) and the first combo seems to be reset. If I scroll once again, another combo change value.


Solution

  • I all,

    Thanks to the answers on QT forum, I solved my issue. Here is the solution I implemented : forum.qt.io/topic/110624/qml-and-combobox-inside-tableview

    Hope it will be helpfull.