qt - How to outsource qml listview delegate -


my delegate grew pretty big. want put in dedicated file. have make work? need clearifications on how import , instantiate delegate. future readers complete howto fine.

you can have property property component delegatecomponent : qt.createcomponent("file.qml") , use delegate. or directly delegate: qt.createcomponent("file.qml").

you can use loader delegate, , set source property desired file. level of abstraction allows different items in list instantiate different qml files, practically achieving different delegates.

normally, don't need import anything, unless component registered part of external module. qml files part of projects work, no imports needed.

you can click on root object of delegate component (not on component single allowed child), go "refactoring" , click "move component separate file". result in component { thenewqmlfile { } } thenewqmlfile replace content of object tree promoted new source. can work in form, without need use first 2 techniques.

because of qml's dynamic scoping, can use model roles external qml files well, resolved long object instantiated in correct context, i.e. delegate of view model, providing roles.

3 possible ways it:

delegate: qt.createcomponent("delegatetype.qml")  delegate: component { delegatetype { } }  delegate: component { loader { source: "delegatetype.qml"} } // here source can come model role 

actually, seems explicitly wrapping in component not necessarily, happens implicitly well. last 2 work this:

delegate: delegatetype { }  delegate: loader { source: "delegatetype.qml"}  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -