Can I add multistate to a single button
Tugpsx
Posts: 738
Im looking to reduce the interface by adding multiple press state to a single button.
Rather than have individual buttons for Auto, On, Off. I would like to have a sinle button "State" when pressed 3 times would cycle throught Auto, On and Off. On the 4th press it would be back to Auto. I guess i could do it with a dropdown selection list also.
Any thoughts?
Comments
A DzButton has only the two states, but there are other controls you could use:
DzComboBox (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/combobox_dz) supports multi-state
DzComboEdit (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/comboedit_dz) supports multi-state and text selection (and optionally editing)
DzCheckListItem (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/checklistitem_dz) supports tri-state
DzEnumSlider (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/enumslider_dz) provides multi-state in a labeled integer value
You could simply do it in a slot connected to the button's clicked signal.
Just increment a variable each click, the fourth click resetting the value.
Try this out, see if it does what you want:
(function () {
// a dialog
var wDlg = new DzDialog();
wDlg.caption = "tri-state button";
wDlg.width = 200;
wDlg.height = 200;
//a button
var wTriButton = new DzPushButton(wDlg);
// set the initial state of the button
var nState = 0; // <--- THIS hold the button state, read it from wherever
wTriButton.text = "Off";
// make it pretty
var wLayout = new DzGridLayout(wDlg);
wLayout.addWidget(wTriButton, 1, 1, 1, 1);
// connect a toggle counter
connect(wTriButton, "clicked()", doToggle);
// records the state of the button for each click
function doToggle() {
nState += 1;
if (nState > 2) {
nState = 0;
}
//update the button text
updateButton();
}
// updates the button text based on the toggle state
function updateButton() {
var txt = "";
switch (nState) {
case 0:
txt = "Off";
break;
case 1:
txt = "On";
break;
case 2:
txt = "Auto";
break;
}
// set the button's text
wTriButton.text = txt;
}
wDlg.exec();
})();
edited text("Off") to "Off" so it "just works"
Qt's UI guidelines say that to select exactly one from a set of mutually exclusive options you users would expect to see radio buttons inside a group because all the choices are apparent, or a combo box if space is a premium. I think a command button might be slightly confusing because a command button is supposed to initiate an action, and it won't be obvious to the user what the button does, what the states are, etc..
In your case, I think a combobox is most appropriate.
@ghost_of_delete_key Thanks this is what i was looking for but as TheMysteryIsThePoint said it may be best to present the users with the combobox rather than having to explain that the button has 3 states. It was a good Idea at one point. I will find future use for the assisted code again Thanks.
Darwin called this...
Evolution.