Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Feeding data from QSortFilterProxyModel to a BarSeries
Qt 6.11 is out! See what's new in the release blog

Feeding data from QSortFilterProxyModel to a BarSeries

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 950 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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?

    Regards

    ? 1 Reply Last reply
    0
    • ? A Former User

      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?

      Regards

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

      C++

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

      QML

      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().

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved