ok button

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

ok button

Post by Surendranath » Sat Jan 26, 2013 1:16 am

Could u please post a piece of code on the use of a push button to close a dialog.
I have a dialog with some radiobuttons, a combobox and a pushbutton. When the pushbutton is clicked I want the dialog closed and the values of the selected item and the state of the radio buttons returned.

Thanks

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: ok button

Post by andrew » Sat Jan 26, 2013 8:44 am

A simple example for this is the BitmapExport Dialog in:

scripts/File/BitmapExport/BitmapExport.js
and
scripts/File/BitmapExport/BitmapExportDialog.ui

Creating the dialog:

Code: Select all

var dialog = WidgetFactory.createDialog(BitmapExport.includeBasePath, "BitmapExportDialog.ui", appWin);
Getting a pointer to a GUI element:

Code: Select all

var widthEdit = dialog.findChild("Width");
Running the dialog:

Code: Select all

if (!dialog.exec()) {
    // dialog cancelled
}
Getting the user input from the dialog:

Code: Select all

widthEdit.getValue();

Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: ok button

Post by Surendranath » Sat Jan 26, 2013 3:36 pm

Thanks. That did the job.
I am able to create a dialog using qcreator and use it my program.
one thing though I could not get the degree symbol in the text for the radiobutton using unicode

I was actually trying to create a dialog programmatically.

Please check the following code. (I am just curious to make this work)
What should I do to get the chosen index from combo box and the state of the radio button and close the dialog when the push button is clicked.

Code: Select all


function InsertBlockDialog() {
	
    this.choice = 0;
    this.angle = 0;
    this.blocks = new Array("Cell", "Capacitor", "Inductor", "Resistor", "AC", "Instr", "Terminal");
     var dialog = new QDialog(RMainWindowQt.getMainWindow());

    var vbl = new QVBoxLayout();
    var RBW = new QWidget();
    var RBLO = new QHBoxLayout();
    var RBWL = new QLabel("Value :");
    RBLO.addWidget(RBWL, 0, 0);
    RBW.setLayout(RBLO);
    vbl.addWidget(RBW, 0, 0);
 
   	
    var comboBox = new QComboBox();
    for (var i = this.blocks.length - 1; i >= 0; --i) {
         comboBox.insertItem(0, this.blocks[i]);
    }

   
    var pb = new QPushButton("Done", dialog);
	
    var rb1 = new QRadioButton("0\u00B0");
    rb1.checked = true;
    var rb2 = new QRadioButton( "90\u00B0");
    var rb3 = new QRadioButton("180\u00B0");
    var rb4 = new QRadioButton("270\u00B0");
	
    
    var RBW = new QWidget();
    var RBLO = new QHBoxLayout();
    var RBL = new QLabel("Angle :");
    RBLO.addWidget(RBL, 0, 0);
    RBLO.addWidget(rb1, 0, 0);
    RBLO.addWidget(rb2, 0, 0);
    RBLO.addWidget(rb3, 0, 0);
    RBLO.addWidget(rb4, 0, 0);
    RBW.setLayout(RBLO);

    vbl.addWidget(RBW, 0, 0);
    RBW.setLayout(RBLO);

	
    var dialogLayout = new QVBoxLayout();
    dialogLayout.addWidget(comboBox, 0, 0)
    dialogLayout.addWidget(RBW, 0, 0);
    dialogLayout.addWidget(pb, 0, 0);	
    dialog.setLayout(dialogLayout);
    dialog.setWindowTitle("::: Block  :::");	
		
    pb.clicked.connect(function () {
    	
        this.choice = comboBox.currentIndex;
        if (rb1.checked)
            this.angle = 0;
        else if (rb2.checked)
            this.angle = 90;
        else if (rb3.checked)
            this.angle = 180;
        else if (rb4.checked)
            this.angle = 270;
    });
    
    dialog.exec();  
	
};

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”