qt - Binding specific item of a ListModel to a Component -


i building application hsqml. first encounter qml, second ever work in qt, , first larger project haskell, forgive ignorance.

in ui, have tabview. first tab contains listview bound model , displays list of items. double-clicking item in listview opens new tab component correctly shows item's details (my guess virtue of new tab inheriting context list item clicked).

now, objective open tab in create new item model. idea create blank data item (optionally adding model), , "load" same component type used editing existing items. scoured qml's documentation , not find remotely related, makes me think approach flawed.

tabview {     id : roottabs      tab {         listview {             model : autolistmodel {                 source : workflowmodel // sort of hsqml specific, data comes list haskell             }             delegate : rectangle {                 text {                     text : modeldata.name                 }                  mousearea {                     anchors.fill : parent                      // part works because new component inherits modeldata current context                     // new tab has correct data                     ondoubleclicked : {                         roottabs.addtab(modeldata.name, qt.createcomponent("workflowview.qml"))                         roottabs.currentindex = roottabscount - 1                     }                 }             }         }          button {             text : "create workflow"              // part in question - how assign newly appended data comp?             onclicked : {                 wmodel.appendblank()                 comp = qt.createcomponent("workflowview.qml")                 var tab = roottabs.addtab("new workflow", comp)                 comp.statuschanged.connect(tabloaded)             }         }     } } 

workflowedit.qml:

rectangle {     textfield {         id : nameinput         text : modeldata.name         binding {             target : modeldata             property : "name"             value : nameinput.text         }     } } 

i think have you're looking for. little tricky because tab loaders. matter of creating property tab qml type place store model index. , since tabs children of tabview, new tabs can parented tabview instead of using addtab() method. note model used listmodel.

main.qml

import qtquick 2.7 import qtquick.controls 1.4 import qtquick.window 2.2  window {     visible: true     width: 640     height: 480      tabview {         id : roottabs         anchors.fill: parent          listmodel {             id: listmodel             listelement { car: "toyota" }             listelement { car: "chevrolet" }             listelement { car: "honda" }             listelement { car: "daihatsu" }             listelement { car: "ford" }             listelement { car: "nissan" }             listelement { car: "hyundai" }             listelement { car: "acura" }         }          mytab {             title: "default"              item {                  listview {                     id: listview                     anchors { fill: parent; bottommargin: 240 }                     model : listmodel                      delegate : rectangle {                         width: parent.width                         height: 40                         text {                             text : car                             color: "black"                             font.pointsize: 20                         }                          mousearea {                             anchors.fill : parent                             ondoubleclicked : {                                 var mytab = qt.createcomponent("mytab.qml")                                 var workflow = qt.createcomponent("workflow.qml")                                 mytab.createobject(roottabs, { "title": car, "modelindex": index, "sourcecomponent": workflow });                                 roottabs.currentindex = roottabs.count - 1                             }                         }                     }                 }                  button {                     anchors {fill: parent; topmargin: 240 }                     text : "create workflow"                      onclicked : {                         listmodel.append( { "car" : "new car" } )                         var mytab = qt.createcomponent("mytab.qml")                         var workflow = qt.createcomponent("workflow.qml")                         mytab.createobject(roottabs, { "title": "new workflow", "modelindex": listmodel.count - 1 , "sourcecomponent": workflow });                     }                 }             }         }     } } 

mytab.qml

import qtquick 2.0 import qtquick.controls 1.4  tab {     property int modelindex } 

workflow.qml

import qtquick 2.0 import qtquick.controls 1.4  rectangle {     textfield {         id : nameinput         text : listmodel.get(modelindex).car         ontextchanged: {             // update model using modelindex. observe updates in listview             listmodel.set(modelindex, { "car" : text })         }     } } 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -