android - qml How to use loader within tabview -
i can not find way use loader fill tab within tabview. loader works fine when outside of tabview (ie if remove multi line comment characters @ top of maintrial.qml , loader plus connections @ top. if move loader in line child of tab, error "cannot assign multiple values singular property. neither can address loader outside of tabview using menuloader.source or column1.menuloader.source or other variants. here main file. (the other 2 files define signals included can see signals work). doing wrong?
edit: (good ole law of permutations , combinations) discovered if make connections declaration, child of loader on tab, problem goes away. have 1 "value" assigned on tab - being loader , can load qml item per tab.
//maintrial
import qtquick 2.2 import qtquick.controls 1.1 import qtquick.layouts 1.1 item { id: trial width: 360 height: 360 columnlayout { id: column1 spacing:150 item {layout.fillheight: true} tabview { id: tabpages tab { id: welcomepage title: "welcome" // /* loader{ id: menuloader source: "maintrial1.qml" anchors.top: parent.top connections { id: menuconnection ignoreunknownsignals: true target: menuloader.item onmaintrial3: { menuloader.source = "maintrial3.qml" console.log("originated " + origin) } onmaintrial1: { menuloader.source = "maintrial1.qml" console.log("originated " + origin) } } } } tab { id: statuspage title: "status" } } } }
// maintrial1 (with 1 signal definition)
this file defines 1 of signals used load next qml object. included here can see signal works).
import qtquick 2.2 import qtquick.controls 1.1 import qtquick.layouts 1.1 item { id: page1 property string origin: "hello" signal maintrial3(string origin) columnlayout { spacing: 15 rectangle { width: 100 height: 62 color: "red" mousearea { anchors.fill: parent onclicked: { maintrial3("origin = mousearea") } } } button { text: "sorting , scanning" onclicked: { maintrial3(origin = "from button") } } } }
//maintrial3 (with other signal definition)
this file defines other signal used reload previous qml object. included here can see both signals work when 1 clicks on rectangles).
import qtquick 2.2 import qtquick.controls 1.1 import qtquick.layouts 1.1 item { id: page3 property string origin: "hello" signal maintrial1(string origin) gridlayout { columnspacing: 5 rowspacing: 5 columns: 1 rectangle { width: 100 height: 62 color: "blue" mousearea{ anchors.fill: parent onclicked: { maintrial1(origin = "from mousearea1") } } } rectangle { width: 100 height: 62 color: "blue" mousearea{ anchors.fill: parent onclicked: { maintrial1("from mousearea2") } } } } }
ok took code, used bit, , customized rest load single tab make talking around bit easier. it's not posted should show how to:
- receive signal when clicked inside tab.
- where , how load tabs.
with should have solid foundation further customize , add in two, three, etc... tabs , dynamically change them based upon signals in example.
importantly, tab
loader
there no need define inner loader
. next i'm not entirely experienced qml yet (qwidget more thing) connections
using seemed cause problems, i'm not sure entirely needed, removed them example.
in example load single qml file in tab , send signal when click on either blue rectangle or red rectangle inside tab loaded.
you'll able see print out in console. i've left comment in signal handler change source
of tab
, dynamically load next tab
.
enjoy!
tabviewtest.qml
import qtquick 2.2 import qtquick.controls 1.1 import qtquick.layouts 1.1 item { id: tabviewtest width: 360 height: 360 tabview { id: tabview width: parent.width height: parent.height tab { title: "welcome" id: dynamictab anchors.top: parent.top // [1] specify source url load content. source: "rectanglestab.qml" // [2] define signal within tab // connected 'contentsclicked' signal // in each tab qml file. signal tabcontentsclicked( string rectcolor ) // [3] implement signal handler. ontabcontentsclicked: { console.log( "clicked on a", rectcolor, "rectangle." ) // [4] user has clicked somewhere within tab // optionally source or sourcecomponent here // comment below. // // make sure has signal called 'contentsclicked' // // dynamictab.source = "someothertab.qml" } onloaded: { console.debug( "loaded", source ); // [4] here's key action, connect signal // 'contentsclicked' our signal // 'tabcontentsclicked' loaded item // i.e. rectanglestab.qml dynamictab.item.contentsclicked.connect(tabcontentsclicked) } } tab { id: statustab title: "status" } } }
rectanglestab.qml
import qtquick 2.0 import qtquick.layouts 1.1 rectangle { id: rectanglestab width: parent.width height: parent.height color: "black" signal contentsclicked( string rectcolor ) gridlayout { width: parent.width height: parent.height columnspacing: 5 rowspacing: 5 columns: 1 rectangle { width: parent.width height: 120 color: "blue" mousearea{ anchors.fill: parent onclicked: { contentsclicked( "blue" ) } } } rectangle { width: parent.width height: 120 color: "red" mousearea{ anchors.fill: parent onclicked: { contentsclicked( "red" ) } } } } }
Comments
Post a Comment