Solved Visibility Toggling
-
Is it possible to toggle the visibility of an Item such as a SpinBox using a ComboBox?
I want the Item (Spin Box) to show up when certain selections in a ComboBox, and not show up for other choices.Thanks!
-
-
@jsulm I still don't get how to do it. I tried using a switch statement but it doesn't work. This is what I have so far.
ComboBox{
id: comboBox
textRole: "choice"
model: ListModel{
ListElement{
choice: "visible"
value: 0
}
ListElement{
choice:"invisible"
value: 1
}
}
}SpinBox{
id: spin
visible:{
switch(comboBox.currentIndex)
{
case 0: setVisible(true)
case 1: set Visible(false)
}
}
}
}
It gives me a warning saying that there is an undetermined non-empty case blockThanks!
-
@GoldRatio Now I see you're using QML - you should mention this.
I'm not a QML expert, but shouldn't there be something like:switch(comboBox.currentIndex) { case 0: setVisible(true); break; case 1: setVisible(false); break; default: setVisible(true); break; }
-
@jsulm said in Visibility Toggling:
@GoldRatio Now I see you're using QML - you should mention this.
I'm not a QML expert, but shouldn't there be something like:switch(comboBox.currentIndex) { case 0: setVisible(true); break; case 1: setVisible(false); break; default: setVisible(true); break; }
close, but not quite, this should do it:
//inside combobox onCurrentIndexChanged:{ switch(currentIndex) { case 0: spin.visible = true; break; case 1: spin.visible = false; break; default: spin.visible = true; break; } }
-
This post is deleted! -
Thanks! I figured out a different way and forgot to check the forum. I used:
onCurrentIndexChanged:{
visible: {
switch(currentIndex)
{
case 0: return true;
case 1: return false;
default: return false;
}
}
}Thanks for all of the help tough!