Programmatically generated dialogue

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
User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Programmatically generated dialogue

Post by hungerburg » Mon May 23, 2011 3:04 pm

The new scripting interface did remove some convenience functions that were present in the previous QSA, http://doc.trolltech.com/porting-qsa.html - still, I rather not design the entry dialogue in my script with an extra app, but layout programmatically the inputs as taken from the data structure at the heart of my script.

Is there a way to instantiate e.g. a tab widget ( http://doc.qt.nokia.com/qtabwidget.html ) from script and have a layoutmanager do the sizing etc.? Something like that:

Code: Select all

var D = new Dialog();
D.newTab(foo);
D.add(bar);

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

Post by andrew » Mon May 23, 2011 3:14 pm

Yes, you can of course do everything programmatically as well using the appropriate script classes from the Qt API (QDialog, QTabWidget and the QLayout classes, e.g. QFormLayout).

The Qt API doc has documentation for all these Qt classes and also examples in C++ which should be relatively easy to map to ECMAScript:
http://doc.qt.nokia.com/latest/classes.html

User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Post by hungerburg » Wed May 25, 2011 11:57 am

Thank you for encouragement. Below code may serve as a starting point for others, so here is what goes into myAction.prototype.beginEvent():

Code: Select all

// base of a dialogue that contains a tab widget
var tabDialog = new QDialog(appWin);
var tabWidget = new QTabWidget();

// first tab: widget and layout
var T1W = new QWidget();
var T1L = new QVBoxLayout();
// first row in first tab: widget and layout
var T11W = new QWidget();
var T11L = new QHBoxLayout();
var T11WL = new QLabel("Foo 11");
var T11WE = new QLineEdit();
T11L.addWidget(T11WL, 0, 0);
T11L.addWidget(T11WE, 0, 0);
T11W.setLayout(T11L);
// finish tab
T1L.addWidget(T11W, 0, 0);
T1W.setLayout(T1L);
tabWidget.addTab(T1W, "Tab &1");

// dialogue buttons
var buttonBox = new QDialogButtonBox();
buttonBox.addButton(QDialogButtonBox.Open);
buttonBox.addButton(QDialogButtonBox.Ok);
buttonBox.addButton(QDialogButtonBox.Cancel);

// finish dialogue
var dialogLayout = new QVBoxLayout();
dialogLayout.addWidget(tabWidget, 0, 0);
dialogLayout.addWidget(buttonBox, 0, 0);
tabDialog.setLayout(dialogLayout);
tabDialog.setWindowTitle("bar");
tabDialog.exec(); 
Basic creation is only a little more involved than with QSA. Still have to do the connects() etc.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”