Programmatically generated dialogue

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

Moderator: andrew

Programmatically generated dialogue

Postby 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
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm

Postby 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
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

Postby 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.
User avatar
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 2 guests