Teach Me How To Checkbox

I've got a script I've been working on that will let the user select scene lights via a checkbox. What happens afterward is irrelevant at this point, because I'm trying to figure out how to get the checkbox dialog to actually DO anything. Right now I've got this code:

// DAZ Studio version 4.12.1.118 filetype DAZ Scriptvar oStyle = App.getStyle(); 	var nBtnHeight = oStyle.pixelMetric( "DZ_ButtonHeight" ); 	var wDlg = new DzBasicDialog();	var wLyt = new DzVBoxLayout (wDlg);	wLyt.autoAdd = true;		var oDlgWgt = wDlg.getWidget(); 	wDlg.caption = "This is a thing"; 	var sKey = wDlg.caption.replace( / /g, "" ) + "Dlg"; 	oDlgWgt.objectName = sKey;	var col1;		 col1 = new DzTextBrowser(wDlg);	 col1.text = qsTr("Select scene lights");	 wDlg.addWidget(col1);var litelist = Scene.getLightList();var lite;var lyt;var sel;var nam;var ind;var wCheckWgt;var chk;for (i=0; i<litelist.length; i++) {	lite = Scene.getLight(i);	ind = Scene.findNodeIndex(lite);	sel = Scene.getNode(ind);	sel.setPrimarySelection;	wCheckWgt = new DzCheckBox( wDlg );	wCheckWgt.name = "check" + i;		wCheckWgt.setFixedHeight( nBtnHeight );	wCheckWgt.text = sel.getName();	wDlg.addWidget( wCheckWgt );}	var sizeHint = oDlgWgt.minimumSizeHint; 	wDlg.setFixedSize( sizeHint.width, sizeHint.height );  					if( wDlg.exec() ){		var clk = [];		var fnd = []; 		var chk = []; 		var wdg;		for (i=0; i<litelist.length; i++) {			fnd = qsTr("check" + i);			chk = wDlg.findChildOfWidget(fnd).name;			wdg = wDlg.getWidget(chk);						if (wdg.isChecked) {							print(chk + " is checked");				}			}						}	

Hopefully I'm doing a lot of unnecessary steps and the real process is much simpler. What the code SHOULD be doing is checking on execution to see which boxes are checked. I've tried several different methods, like changing "if (wdg.isChecked)" to "...isChecked = true", "...checked" and so on, and either no results are returned, or all results are returned regardless of what's checked. Am I looking in the wrong place for the parameter? Is there an extra declaration I should be making? What the dilly, yo?

Comments

  • This seems to work. 

    The property on the check box is 'checked'.  The findChildOfWidget gets the checkbox instance for us.  The getWidget method (inherited from DzWidget?) appears to return the DzBasicDialog instance in your case, which is odd and not what you are after.  According to the docs it returns the 'wrapped QWidget'.

    var oStyle = App.getStyle(); 	var nBtnHeight = oStyle.pixelMetric( "DZ_ButtonHeight" ); 	var wDlg = new DzBasicDialog();	var wLyt = new DzVBoxLayout (wDlg);	wLyt.autoAdd = true;		var oDlgWgt = wDlg.getWidget(); 	wDlg.caption = "This is a thing"; 	var sKey = wDlg.caption.replace( / /g, "" ) + "Dlg"; 	oDlgWgt.objectName = sKey;	var col1;		 col1 = new DzTextBrowser(wDlg);	 col1.text = qsTr("Select scene lights");	 wDlg.addWidget(col1);var litelist = Scene.getLightList();var lite;var lyt;var sel;var nam;var ind;var wCheckWgt;var chk;for (i=0; i<litelist.length; i++) {	lite = Scene.getLight(i);	ind = Scene.findNodeIndex(lite);	sel = Scene.getNode(ind);	sel.setPrimarySelection;	wCheckWgt = new DzCheckBox( wDlg );	wCheckWgt.name = "check" + i;		wCheckWgt.setFixedHeight( nBtnHeight );	wCheckWgt.text = sel.getName();	wDlg.addWidget( wCheckWgt );}var sizeHint = oDlgWgt.minimumSizeHint; wDlg.setFixedSize( sizeHint.width, sizeHint.height );  					if( wDlg.exec() ){		var clk = [];		var fnd = []; 		var chk = []; 		var wdg;		for (i=0; i<litelist.length; i++) {			fnd = qsTr("check" + i);			chk = wDlg.findChildOfWidget(fnd);			if (chk.checked) {							print(chk.name + " is checked");				}			}		}

     

  • GordigGordig Posts: 6,315

    Thank you! Now I can get to work on what I actually want this script to do.

Sign In or Register to comment.