how to specify no icon.source in TabBar
-
Hi all -
I have this passage:
ListModel { id: prefsModel ListElement { name: "Profile && Accounts"; image: "" } ListElement { name: "Device"; image: ""} ListElement { name: "Site"; image: "" } ListElement { name: "BODY OF WATER"; image: "qrc:/icons/add.svg" } } Repeater { model: prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: model.image bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }This works, but for each of the ListElements with empty strings for the image property, I get an error: "Unable to assign [undefined] to QUrl." What is the preferred method for doing this? (I actually customized TabButton, but left that out from this example, so I can modify that if appropriate.)
Thanks...
-
Hi all -
I have this passage:
ListModel { id: prefsModel ListElement { name: "Profile && Accounts"; image: "" } ListElement { name: "Device"; image: ""} ListElement { name: "Site"; image: "" } ListElement { name: "BODY OF WATER"; image: "qrc:/icons/add.svg" } } Repeater { model: prefsModel Tabbutton_custom { text: qsTr(model.name) icon.source: model.image bgColor: auxTabBar.bgColor imageSize: auxTabBar.height / 2 } }This works, but for each of the ListElements with empty strings for the image property, I get an error: "Unable to assign [undefined] to QUrl." What is the preferred method for doing this? (I actually customized TabButton, but left that out from this example, so I can modify that if appropriate.)
Thanks...
-
@mzimmers said in how to specify no icon.source in TabBar:
icon.source: model.image
can not you check if model.image is empty or not? Set it if not empty.
icon.source: model.image === "" ? Qt.resolvedUrl("") : model.imageThis post is deleted! -
@mzimmers said in how to specify no icon.source in TabBar:
icon.source: model.image
can not you check if model.image is empty or not? Set it if not empty.
icon.source: model.image === "" ? Qt.resolvedUrl("") : model.image -
It turns out that @JoeCFD was right. The problem wasn't with my forming of the QString; it was that my code is a little more complicated than the snippet I posted above:
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 } }I'm trying to make the model selection dynamic, which seems to work, but my test for which model is in use isn't working right.
I'll mark this as solved and open a new topic.
Thanks...
-
M mzimmers has marked this topic as solved on