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
ok button
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: ok button
A simple example for this is the BitmapExport Dialog in:
scripts/File/BitmapExport/BitmapExport.js
and
scripts/File/BitmapExport/BitmapExportDialog.ui
Creating the dialog:
Getting a pointer to a GUI element:
Running the dialog:
Getting the user input from the dialog:
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);
Code: Select all
var widthEdit = dialog.findChild("Width");
Code: Select all
if (!dialog.exec()) {
// dialog cancelled
}
Code: Select all
widthEdit.getValue();
-
- Junior Member
- Posts: 16
- Joined: Mon Jan 07, 2013 9:43 am
Re: ok button
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.
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();
};