How to Identify Model In Use?
-
Hi all -
I have a Repeater for a custom TabBar. The contents of the TabButtons is to depend on which model is applied to the repeater. Here's what I'm trying:
Repeater { model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }My error seems to be here:
icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")The "model === prefsModel" always seems to evaluate as false. I imagine I'm improperly forming the test. How can I determine which model is in use here?
Thanks...
-
@piervalli interesting. It's not working for me; perhaps I'm not using it properly?
ListModel { id: prefsModel objectName: "prefsModel" ListElement { name: "Profile && Accounts"; image: "" } ListElement { name: "Device"; image: ""} ListElement { name: "Site"; image: "" } ListElement { name: "ZONE"; image: "qrc:/icons/add.svg" } } Repeater { model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: (model.objectName === "prefsModel" && model.image !== "") ? model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }@mzimmers This looks like a scoping issue. Unless the Repeater is the top level Item the lower Items won't see the "model".
Repeater { id: repeater model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(repeater.model.name) icon.source: (repeater.model.objectName === "prefsModel" && repeater.model.image !== "") ? repeater.model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }Or you could use parent.model in this case.
Are you not getting all sorts of errors in the application output?
-
Hi all -
I have a Repeater for a custom TabBar. The contents of the TabButtons is to depend on which model is applied to the repeater. Here's what I'm trying:
Repeater { model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }My error seems to be here:
icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")The "model === prefsModel" always seems to evaluate as false. I imagine I'm improperly forming the test. How can I determine which model is in use here?
Thanks...
-
@piervalli interesting. It's not working for me; perhaps I'm not using it properly?
ListModel { id: prefsModel objectName: "prefsModel" ListElement { name: "Profile && Accounts"; image: "" } ListElement { name: "Device"; image: ""} ListElement { name: "Site"; image: "" } ListElement { name: "ZONE"; image: "qrc:/icons/add.svg" } } Repeater { model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: (model.objectName === "prefsModel" && model.image !== "") ? model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } } -
@piervalli interesting. It's not working for me; perhaps I'm not using it properly?
ListModel { id: prefsModel objectName: "prefsModel" ListElement { name: "Profile && Accounts"; image: "" } ListElement { name: "Device"; image: ""} ListElement { name: "Site"; image: "" } ListElement { name: "ZONE"; image: "qrc:/icons/add.svg" } } Repeater { model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: (model.objectName === "prefsModel" && model.image !== "") ? model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }@mzimmers This looks like a scoping issue. Unless the Repeater is the top level Item the lower Items won't see the "model".
Repeater { id: repeater model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(repeater.model.name) icon.source: (repeater.model.objectName === "prefsModel" && repeater.model.image !== "") ? repeater.model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }Or you could use parent.model in this case.
Are you not getting all sorts of errors in the application output?
-
@mzimmers This looks like a scoping issue. Unless the Repeater is the top level Item the lower Items won't see the "model".
Repeater { id: repeater model: (navBar.tabIndex < 4) ? zoneModel : prefsModel Tabbutton_custom { text: qsTr(repeater.model.name) icon.source: (repeater.model.objectName === "prefsModel" && repeater.model.image !== "") ? repeater.model.image : Qt.resolvedUrl("") bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }Or you could use parent.model in this case.
Are you not getting all sorts of errors in the application output?
-
M mzimmers has marked this topic as solved on
-
@fcarney well...that fixed it. Interestingly enough, I don't find it necessary to scope the model in the text: line...not sure why it would be different for item.source.
And no, I'm not getting any errors.
But...I'll consider it solved. Thanks!