qt - How to put attached properties to child item -


let's assume have component this

rowlayout {     myitem {         layout.fillwidth: true         layout.fillheight: true         ... // other properties     }     myitem {         layout.fillwidth: true         layout.fillheight: true         ... // other properties     } } 

in myitem.qml defined

rectangle {     ... // other properties     // layout.fillwidth: true     // layout.fillheight: true } 

can put layout.fillwidth myitem, don't need repeat in rowlayout ?

can put layout.fillwidth myitem, don't need repeat in rowlayout ?

i think question has answer in it: if don't want repeat, use repeater type. documentation states that

items instantiated repeater inserted, in order, children of repeater's parent. insertion starts after repeater's position in parent stacking list. allows repeater used inside layout.

the example follows in documentation uses row same approach can applied other layouts, e.g. rowlayout. actually, works type attached properties per repeater nature ("insert items inside parent").

here example. assume have defined example type.

import qtquick 2.5  rectangle {     property alias text: inner.text     color: "steelblue"      text {         id: inner         anchors.centerin: parent         font.pixelsize: 30     }     } 

we can add layout properties our example type inside repeater, instance this:

import qtquick 2.5 import qtquick.window 2.2 import qtquick.layouts 1.1  window {     id: window     width: 600     height: 400     visible: true      rowlayout {         id: row         anchors.fill: parent          repeater {             model: 6                             delegate : example {                 text: index                 layout.fillwidth: true    // layout options added in delegate                 layout.fillheight: true                 layout.alignment: qt.aligncenter                 layout.maximumwidth: parent.width / model.length             }         }     } } 

the model property of repeater can either array of strings or model, usual.

this approach flexible enough combine several repeaters create more complex structures. see instance following example in text used fill screen inside gridlayout:

import qtquick 2.5 import qtquick.window 2.2 import qtquick.layouts 1.1  window {     id: window     width: 600     height: 400     visible: true      gridlayout {         id: grid         anchors.fill: parent         rows: 2         columns: 6          repeater {             model: grid.columns             text {                 layout.fillwidth: true                 layout.fillheight: true                 layout.row: 0                 layout.column: index                 verticalalignment: text.alignvcenter                 horizontalalignment: text.alignhcenter                 text: index + 1    // index of repeater text             }         }          repeater {             model: grid.columns             text {                 layout.fillwidth: true                 layout.fillheight: true                 layout.row: 1                 layout.column: index                 verticalalignment: text.alignvcenter                 horizontalalignment: text.alignhcenter                 text: index + 7             }         }     } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -