i'm trying dynamically create tab
s in qml. code below simple example of want do.
import qtquick 2.0 import qtquick.controls 1.0 applicationwindow{ id:win tabview{ id:tb anchors.fill:parent mousearea{ anchors.fill:parent onclicked:tb.loadtab() } component{ id:viewcomp rectangle{ anchors.fill:parent color:"black" } } function loadtab(){ var t=addtab("x",viewcomp) t.item.color="blue" //line 20 } } }
addition of first tab
works expected. however, after other tab
added triggers error:
typeerror: cannot set property 'color' of null`.
i tried access tab
with gettab()
change color, same error. can explain doing wrong?
finally got around , tried fix , successful. decided post answer in case stumbles on google , has similar problem.
the solution set currentindex
new tab
, set properties of tab
. means function loadtab()
looks this:
loadtab(){ var c_tab=currentindex var t=tb.addtab("x",viewcomp) currentindex=count-1 t.item.color="blue" currentindex=c_tab }
this works nicely.
Comments
Post a Comment