Page 1 of 1

Programmatically generated dialogue

Posted: Mon May 23, 2011 3:04 pm
by hungerburg
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);

Posted: Mon May 23, 2011 3:14 pm
by andrew
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

Posted: Wed May 25, 2011 11:57 am
by hungerburg
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.