Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved Registering a ListModel property change with a specific delegate

    General and Desktop
    2
    2
    135
    Loading More Posts
    • 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.
    • devDawg
      devDawg last edited by

      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!

      Anything worthwhile is never achieved easily.

      1 Reply Last reply Reply Quote 0
      • V
        VRonin last edited by

        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.

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 1
        • First post
          Last post