Feeding data from QSortFilterProxyModel to a BarSeries

  • Hi,

    I am trying to show data from a QSortFilterProxyModel (C++ side) in a BarSeries (QML side) but struggle on the general approach.

    Can I give my model to the BarSeries in any way or do I need to write some Q_INVOKABLE methods on the C++ side to get the data?


  • OK, now I did it like this:
    Create a Q_INVOKABLE that collects data from a column in a QVarianList and call that from the QML side.


    QVariantList ProxyModel::values(int role) const
        QVariantList values;
        int rows = rowCount();
        for (int row = 0; row < rows; ++row) {
            QModelIndex idx = index(row, 0);
        return values;


    ChartView {
        title: "Consumption"
        anchors.fill: parent
        antialiasing: true
        BarSeries {
            id: mySeries
            axisX: BarCategoryAxis { categories: myModel.values(258) }
            BarSet { label: qsTr("Voltage"); values: myModel.values(259) }
            BarSet { label: qsTr("Current"); values: myModel.values(260) }
            BarSet { label: qsTr("Power"); values: myModel.values(261) }
            BarSet { label: qsTr("Energy"); values: myModel.values(262) }

    ...with those role numbers being the ones I defined in roleNames().

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.