DelegateChooser with QSqlTableModel
Unsolved
QML and Qt Quick
-
I have a TableView which displays data from a model which is based on QSQlTableModel. Now depending on the Column I want to load a different delegate.
This is the model:
class QuestionSqlTableModel : public QSqlTableModel { Q_OBJECT public: explicit QuestionSqlTableModel(QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase()); Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override; };
Now I though I could use DelegateChooser for this:
import QtQuick 2.15 import QtQuick.Controls 2.15 import Qt.labs.qmlmodels 1.0 ListView { width: 200; height: 400 ListModel { id: listModel ListElement { type: "info"; ... } ListElement { type: "switch"; ... } ListElement { type: "swipe"; ... } ListElement { type: "switch"; ... } } DelegateChooser { id: chooser role: "type" DelegateChoice { roleValue: "info"; ItemDelegate { ... } } DelegateChoice { roleValue: "switch"; SwitchDelegate { ... } } DelegateChoice { roleValue: "swipe"; SwipeDelegate { ... } } } model: listModel delegate: chooser }
Now what I want to do is this to choose:
DelegateChooser { id: chooser role: "column" DelegateChoice { roleValue: "0"; ItemDelegate { ... } } DelegateChoice { roleValue: "1"; SwitchDelegate { ... } } DelegateChoice { roleValue: "2"; SwipeDelegate { ... } } }
So the question Is how can I get the current column in qml ?