qml - 2 identical ListViews with small differences inside delegate -



qml - 2 identical ListViews with small differences inside delegate -

i've got 2 identical qml files. list 1 of them here, differences of other 1 shown comment lines:

// messageview.qml; diff. threadview.qml shown comment lines import qtquick 2.0 item { property var model property var selectedthread: threadslist.currentitem.mythread property alias spacing: threadslist.spacing signal activated(var selectedthread) id: root listview { anchors.fill: parent id: threadslist model: root.model delegate: rectangle { property var mythread: message // other file contains `thread` instead of `message` here color: threadslist.currentitem == ? "cyan" : index % 2 ? "lightblue" : "lightsteelblue" width: parent.width height: ti.implicitheight messageitem { // other file contains `threaditem` instead of `messageitem` here id: ti anchors.left: parent.left anchors.right: parent.right anchors.verticalcenter: parent.verticalcenter anchors.margins: 8 } mousearea { anchors.fill: parent onclicked: { threadslist.currentindex = index activated(root.selectedthread) } } } } }

these 2 components intended similar-looking list views minor differences in delegate appearance. how merge these 2 files 1 able utilize them this?

merdedview { messageitem { // more property customization } } merdedview { threaditem { // more property customization } }

there little differences within delegate, need extract mutual codes. example, merdedviewdelegate.qml:

rectangle { id: viewitem property var mythread //other properties: color, width, height, ... mousearea { anchors.fill: parent onclicked: { //use attached property in listview viewitem.listview.view.currentindex = index } } }

then create mergedview.qml messageview.qml, except delegate changed alias property:

//mergedview.qml item { property alias delegate: threadslist.delegate //other properties listview { anchors.fill: parent id: threadslist model: root.model } }

finally, can write qml this:

mergedview { delegate: mergedviewdelegate{ mythread: message //or similar messageitem { /* ... */ } } } mergedview { delegate: mergedviewdelegate{ mythread: thread threaditem { /* ... */ } } }

delegates qml qtdeclarative

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -