Programmatically generated dialogue

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

Moderator: andrew

Post Reply
User avatar
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, - 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 ( ) from script and have a layoutmanager do the sizing etc.? Something like that:

Code: Select all

var D = new Dialog();

User avatar
Site Admin
Posts: 6246
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:

User avatar
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);
// finish tab
T1L.addWidget(T11W, 0, 0);
tabWidget.addTab(T1W, "Tab &1");

// dialogue buttons
var buttonBox = new QDialogButtonBox();

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

Post Reply

Return to “QCAD Developers and Contributors”