Important: Please read the Qt Code of Conduct -

Registering a ListModel property change with a specific delegate

  • Hello everyone,

    Apologies in advance for not sharing code. I currently do not have access, but will tomorrow.

    I am using the QCustomPlot API in conjunction with ListView to form an interactive, scrollable list of graphs. The only thing you should know about QCustomPlot, is that it allows you to add multiple "graphs" (or signals) to one plot. I am trying to take advantage of this feature by allowing a user to select a signal and append it to a SPECIFIC delegate.

    So to emulate this, I have made PlotModel.qml, which looks something like this:

    ListModel {
    ListElement {
    name: "plot1"
    outputs: [ 
        ListElement { value: "-"; units: "-"; name: "-"; }

    So by this style of a model, each item in my ListView of plots, would be a plot that could display many signals. What I've been trying to do is sync up changes outputs (say, remove or add a signal) of PlotModel with the correct delegate & I'm not really sure how to do it.

    Any thoughts?

    Thank you!

  • The delegate should only rely on the data in the model. What you can do is save each data series in a separate role and have the delegate use those roles.

    • save the first series: model->setData(QVector<int>{{0,1,2,3,4}},Qt::UserRole);
    • save the second series: model->setData(QVector<int>{{4,3,2,1,0}},Qt::UserRole+1);
    • in the C++ delegate you can call index.model()->itemData(index); to get back a QMap with the series
    • in QML delegate you have to rely on the model naming the roles.

Log in to reply