In this article
Every widget defined in a ui file is exposed to the script engine.
You can get a particular widget through it's name and the method findChild:
For every widget you have access to:
- properties
- public slots
- signals
If a method is not defined as public slot in c++ qt api, it will not be available to the script engine. Some widgets are wrapped so that you have access to additional methods, see next chapter Wrapped widgets.
For complete examples see the page Script dialogs or the tutorial JavaScript Tutorial 1 (documents 740 'QTableWidget interaction' and 742 'Find dialog').
Example:
// Load ui file
var dialog = Banana.Ui.createUi("ch.banana.scripts.find.ui");
// Get the label/widget through it's name
var statusLabel = dialog.findChild('statusLabel');
// Set the text of label/widget
statusLabel.setText('Hello!');
// Connect button box accepted signal to the dialog close method
var buttonBox = dialog.findChild("buttonBox");
buttonBox.accepted.connect(function() {dialog.close();});
Banana.application.progressBar.pause(); // Pause wait cursor
dialog.exec(); // Show the dialog
Banana.application.progressBar.resume(); // Restart wait cursor
Signals
You have three ways to connect signals to methods.
// Method1: Connect a signal to a function
function findNext() {
Banana.console.log('find next');
}
findNextButton.clicked.connect(findNext);
// Method2: Connect a signal to an object method
var object = {}
object.onClicked = function() {
Banana.console.log('clicked');
};
findNextButton.clicked.connect(object, object. onClicked);
// Method3: Connect a signal to an inline function
findNextButton.clicked.connect(
function(){Banana.console.log('clicked');}
);
Wrapped widgets
The widgets listed below have been wrapped to let you use additional methods that are not exposed to the script engine because they are not declared as public slots.
Hereby only the additional available methods are listed. Their usage and parameters correspond to the c++ counterpart.
QObject
Methods:
findChild(name)
QComboxBox
Methods:
addItem(text)
addItems(texts)
count()
insertItem(index, text)
insertItems(index, texts)
removeItem(index)
QTableWidget
Since: Banana Experimental 9.1.0
Properties:
currentColumn
currentRow
Methods:
currentItem()
item(row, column)
setColumnWidth(column, width)
setEditTriggers(triggerFlag)
setHorizontalHeaderLabels(labels)
setColumnCount(columns)
setCurrentCell(row, column)
setRowCount(rows)
QTableWidgetItem
Properties:
background
checkState
flags
foreground
text