The form namespace contains functions and objects for working with UI elements such as buttons, input fields, tables, and dialogs.
All visual elements have the following methods:
void setEnabled(bool enable) - if enable == true the element will be enabled, otherwise it will be disabled.
void setVisible(bool enable) - if enable is true the element will be visible, otherwise it will be hidden.
bool getEnabled() - returns true if the element is enabled.
bool getVisible() - returns true if the element is visible.
Connect
AxScript uses QT signal-slot technology. A signal is emitted when a particular event occurs. A slot is a function that is called in response to a particular signal. Qt's signals and slots mechanism ensures that if you connect a signal to a slot, the slot will be called with the signal's parameters at the right time. Signals and slots can take any number of arguments of any type. They are completely type safe.
You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal. (This will emit the second signal immediately whenever the first is emitted.)
form.connect(element elem, string signal, function(){}) - Creates a connection from the signal in the elem object to the function handler.
Example
let btn =form.create_button("Send signal");form.connect(btn,"clicked",function(){ax.show_message("test","Clicked signal");});let layout =form.create_vlayout();layout.addWidget(btn);let dialog =form.create_dialog("");dialog.setLayout(layout);dialog.exec()
Container
To retrieve data in JSON format from input elements, you must use a container object.
Methods:
1
put
This method adds an element elem with the given id to the container.
2
get
This method gets an element from the container by the given id.
3
contains
This method checks if an element with the given id exists in the container.
4
remove
This method removes the element with the given id from the container.
5
toJson
This method packs the data of all container elements into JSON format.
6
fromJson
This method recovers the values of elements in a container from a JSON string jsonString.
Example
VLayout / HLayout
The vlayout class lines up elements vertically. The hlayout class lines up elements horizontally.
To create a vlayout/hlayout element, use the form.create_vlayout() / form.create_hlayout() function.
Methods:
1
addWidget
Adds element to the end of this box layout.
Example
GridLayout
The gridlayout class lays out elements in a grid.
To create a gridlayout element, use the form.create_gridlayout() function.
Methods:
1
addWidget
Adds the given element to the cell grid, spanning multiple rows/columns. The cell will start at row, col spanning rowSpan rows and colSpan columns.
Example
VLine / HLine
The line element is a simple divider cover.
To create a vline / hline element, use the form.create_vline() / form.create_hline() function.
Example
VSpacer / HSpacer
The spacer element provides blank space in a layout. Normally, you don't need to use this element directly.
To create a vspacer / hspacer element, use the form.create_vline() / form.create_hline() function.
Example
Basic
With hspacer
Label
The label element provides a text display.
element create_label(string text = "") - Constructs a label that displays the text, text.
Methods:
1
text
This property holds the label's text. If no text has been set this will return an empty string.
2
setText
This method sets the label text, text.
Example
TextLine
The textline element is a one-line text editor.
element create_textline(string text = "") - Constructs a textline containing the text, text.
Methods:
1
text
This property holds the textline's text. If no text has been set this will return an empty string.
2
setText
This method sets the textline text, text.
3
setPlaceholder
This method sets the textline placeholder text, text.
4
setReadOnly
This method holds whether the textline is read-only.
Signals:
1
textChanged
This signal is emitted whenever the text changes. The text argument is the new text.
2
textEdited
This signal is emitted whenever the text is edited. The text argument is the new text.
3
returnPressed
This signal is emitted when the Return or Enter key is used.
4
editingFinished
This signal is emitted when the Return or Enter key is used, or if the textline loses focus and its contents have changed since the last time this signal was emitted.
Example
TextMulti
The textmulti element provides a widget that is used to edit and display text.
element create_textmulti(string text = "") - Constructs a textmulti containing the text, text.
Methods:
1
text
This property holds the textmulti's text. If no text has been set this will return an empty string.
2
setText
This method sets the textmulti text, text.
3
appendText
Appends a new paragraph with text to the end of the textmulti.
4
setPlaceholder
This method sets the textmulti placeholder text, text.
5
setReadOnly
This method holds whether the textmulti is read-only.
Example
DateLine
The dateline element provides a widget for editing dates.
element create_dateline(string format = "dd.MM.yyyy") - Constructs a dateline. The format used to display the date of the date edit.
Methods:
1
dateString
This method return the date that is set in the element.
2
setDateString
This method set the date in the element.
Example
TimeLine
The timeline element provides a widget for editing times.
element create_dateline(string format = "HH:mm.yyyy") - Constructs a timeline. The format used to display the time of the time edit.
Methods:
1
timeString
This method return the time that is set in the element.
2
setTimeString
This method set the time in the element.
Example
Combo
The combo element combines a button with a dropdown list.
element create_combo() - Constructs a combo.
Methods:
1
addItem
Adds an item to the combo with the given text.
2
addItems
Adds each of the strings in the given array to the combo. Each item is appended to the list of existing items in turn.
3
setItems
Clears the combo and adds each of the strings in the given array to the combo.
4
clear
Clears the combo.
5
currentText
This method set the current text.
6
setCurrentIndex
This method set the current item by the index.
7
currentIndex
This method return the index of the current item.
Signals:
1
currentTextChanged
This signal is emitted whenever currentText changes. The new value is passed as text.
2
currentIndexChanged
This signal is emitted whenever currentIndex changes. The new index is passed as number.
Example
Spin
The spin element provides a spin box widget.
element create_spin() - Constructs a spin with 0 as minimum value and 99 as maximum value, a step value of 1. The value is initially set to 0.
Methods:
1
value
This method return the value of the spin.
2
setValue
This method set the value of the spin.
3
setRange
Convenience method to set the min, and max values with a single function call.
Signals:
1
valueChanged
This signal is emitted whenever the spin's value is changed. The new value's passed as integer value.
Example
Check
The check element provides a checkbox with a text label.
element create_check(string label= "") - Constructs a checkbox with the given text.
Methods:
1
isChecked
This method return true if the button is checked.
2
setChecked
This method sets the checked state.
Signals:
1
stateChanged
This signal is emitted whenever the check state changes, i.e., whenever the user checks or unchecks it.
Example
Button
The button element provides a command button.
element create_button(string text= "") - Constructs a button with the text text.
Signals:
1
clicked
This signal is emitted when the button is activated.
Example
List
The list element provides an item-based list widget.
element create_list() - Constructs an empty list.
Methods:
1
items
Returns an array of elements.
2
addItem
Inserts the item at the end of the list widget.
3
addItems
Inserts items at the end of the list widget.
4
removeItem
Removes the element at the specified index.
5
itemText
Return the element at the specified index.
6
setItemText
Set the item at the specified index.
7
clear
Removes all items and selections.
8
count
This method return the number of items in the list including any hidden items.
9
currentRow
This method return the row of the current item.
10
setCurrentRow
This method sets the row of the current element at the specified index.
11
selectedRows
Returns an array of selected elements.
12
setReadOnly
This method holds whether the list is read-only.
Signals:
1
currentTextChanged
This signal is emitted whenever the current item changes. currentText is the text data in the current item. If there is no current item, the currentText is invalid.
2
currentRowChanged
This signal is emitted whenever the current item changes. currentRow is the row of the current item. If there is no current item, the currentRow is -1.
3
itemClickedText
This signal is emitted with the specified text when a mouse button is clicked on an item in the list.
4
itemDoubleClickedText
This signal is emitted with the specified text when a mouse button is double clicked on an item in the list.
Example
Table
The table elements provides an item-based table view.
element create_table(string[] headers) - Creates a new table view with the given headers.
Methods:
1
addColumn
This method adds a new column to the table with the specified header.
2
setColumns
This method adds new columns to the table with the specified headers.
3
addItem
Inserts item at the end of the table, item is an array of strings, the string index corresponds to the column index.
4
rowCount
Returns the number of rows.
5
columnCount
Returns the number of columns.
6
text
This property contains the cell text for the specified row and column. If no text is specified, an empty string is returned.
7
setItemText
Set the cell text for the specified row and column.
8
clear
Removes all items from table.
9
setRowCount
Sets the number of rows in this table's.
10
setColumnCount
Sets the number of cols in this table's.
11
currentRow
This method return the row of the current cell.
12
currentColumn
This method return the column of the current cell.
13
hideColumn
Hide the given column.
14
selectedRows
Returns an array of arrays of the selected elements.
15
setReadOnly
This method holds whether the table is read-only.
16
setSortingEnabled
If enable is true, enables sorting for the table
17
resizeToContent
Will automatically resize the section to its optimal size based on the contents of the entire column.
18
setHeadersVisible
If enable is true, the column in the table will be visible, otherwise hidden.
19
setColumnAlign
Sets the alignment in the column. Available values are "left", "right", "center".
Signals:
1
cellChanged
This signal is emitted whenever the data of the item in the cell specified by row and column has changed.
2
cellClicked
This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.
3
cellDoubleClicked
This signal is emitted whenever a cell in the table is double clicked. The row and column specified is the cell that was double clicked.
Example
Panel
The panel element provides a placement of other elements using layout.
element create_panel() - Constructs a panel.
Methods:
1
setLayout
Sets the layout manager for this element to lt.
Example
GroupBox
The groupbox element provides a group box frame with a title.
element create_groupbox(string title, bool checkable) - Constructs a groupbox with the given title. Property checkable holds whether the group box has a checkbox in its title.
Methods:
1
isChecked
This method return true if the checkbox is checked.
2
setChecked
This method sets the checked state.
3
isCheckable
If this property is true, the group box displays its title using a checkbox in place of an ordinary label.
4
setCheckable
If checkable is true, the group box displays its title using a checkbox in place of an ordinary label.
5
setTitle
This method sets the title text of the group box.
6
setPanel
This method sets an element inside a groupbox.
Signals:
1
clicked
This signal is emitted when the check box is activated
Example
ScrollArea
The scrollarea element provides a scrolling view onto another elements.
element create_scrollarea() - Constructs an empty scrollarea.
Methods:
1
setWidgetResizable
This property holds whether the scrollarea should resize the view element.
2
setPanel
This method sets an element inside a scrollarea.
Example
VSplitter / HSplitter
The splitter element implements a splitter widget.
To create a vsplitter / hsplitter element, use the create_vsplitter() / form.create_hsplitter() function.
Methods:
1
setSizes
Sets the child elements respective sizes to the values given in the sizes.
2
addPage
Adds the given elem to the splitter's layout after all the other items.
Signals:
1
splitterMoved
This signal is emitted when the splitter handle at a particular index has been moved to position pos.
Example
Tabs
The tabs element provides a stack of tabbed widgets.
element form.create_tabs() - Constructs a tabs element.
Methods:
1
addTab
Adds a tab with the given elem and title to the tabs.
Example
Stack
The stack element provides a stack of widgets where only one widget is visible at a time.
element create_stack() - Constructs a stack.
Methods:
1
addPage
Appends the given page to the stask and returns the index position.
2
insertPage
Inserts the given page at the given index in the stack.
3
removePage
Removes element from the stack by index.
4
setCurrentIndex
This method set the index position of the widget that is visible;
5
currentIndex
This method return the index position of the widget that is visible;
6
count
This method return the number of elements contained by this stack.
Signals:
1
currentChanged
This signal is emitted whenever the current element changes.
Example
Dialog
The dialog element is implement of dialog windows.
dialog create_dialog(string title) - Constructs a dialog with title.
Methods:
1
setButtonsText
This method sets the text ok_text for button OK and the text cancel_text for button CANCEL.
2
setSize
This method sets the size for the window.
3
setLayout
Sets the layout manager for this window.
4
close
Close window.
5
exec
Shows the dialog as a modal dialog, blocking until the user closes it. If the window is closed by pressing the OK button, the method will return true.
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let b3 = form.create_button("Three");
let layout = form.create_hlayout();
layout.addWidget(b1);
layout.addWidget(b2);
layout.addWidget(b3);
let dialog = form.create_dialog();
dialog.setLayout(layout);
dialog.exec()
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let b3 = form.create_button("Three");
let layout = form.create_vlayout();
layout.addWidget(b1);
layout.addWidget(b2);
layout.addWidget(b3);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
layout form.create_gridlayout()
void layout::addWidget(form.object element, int row, int col, int rowSpan = 1, int colSpan = 1)
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let b3 = form.create_button("Three");
let b4 = form.create_button("Four");
let layout = form.create_gridlayout();
layout.addWidget(b1, 0, 0, 1, 2);
layout.addWidget(b2, 0, 2, 2, 1);
layout.addWidget(b3, 1, 0, 1, 1);
layout.addWidget(b4, 1, 1, 1, 1);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
element form.create_vline()
element form.create_hline()
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let line = form.create_hline();
let layout = form.create_vlayout();
layout.addWidget(b1);
layout.addWidget(line);
layout.addWidget(b2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let line = form.create_vline();
let layout = form.create_hlayout();
layout.addWidget(b1);
layout.addWidget(line);
layout.addWidget(b2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
element form.create_hline()
element form.create_vspacer()
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let layout = form.create_gridlayout();
layout.addWidget(b1, 0, 0, 1, 1);
layout.addWidget(b2, 1, 0, 1, 2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
let b1 = form.create_button("One");
let b2 = form.create_button("Two");
let spacer = form.create_hspacer();
let layout = form.create_gridlayout();
layout.addWidget(b1, 0, 0, 1, 1);
layout.addWidget(spacer, 0, 1, 1, 1);
layout.addWidget(b2, 1, 0, 1, 2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
string label::text();
void label::setText(string text);
let l1 = form.create_label("Text label");
let l2 = form.create_label();
l2.setText(l1.text() + " 2");
let layout = form.create_vlayout();
layout.addWidget(l1);
layout.addWidget(l2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
string textline::text();
void textline::setText(string text);
void textline::setPlaceholder(string text);
void textline::setReadOnly(bool readonly);
textChanged(string text)
textEdited(string text)
returnPressed()
editingFinished()
let tl1 = form.create_textline();
let tl2 = form.create_textline();
tl2.setPlaceholder("test signal");
form.connect(tl1, "textEdited", function(text){
tl2.setText(tl1.text());
});
let layout = form.create_vlayout();
layout.addWidget(tl1);
layout.addWidget(tl2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
string textmulti::text();
void textmulti::setText(string text);
void appendText(string text)
void textmulti::setPlaceholder(string text);
void textmulti::setReadOnly(bool readonly);
let tl1 = form.create_textmulti("test\nmulti\ntext");
let tl2 = form.create_textline();
let layout = form.create_vlayout();
layout.addWidget(tl1);
layout.addWidget(tl2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
string dateline::dateString();
void dateline::setDateString(string date);
let tl1 = form.create_dateline("dd/MM/yyyy");
let layout = form.create_vlayout();
layout.addWidget(tl1);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
string timeline::timeString();
void timeline::setTimeString(string time);
let tl1 = form.create_timeline("HH:mm");
let layout = form.create_vlayout();
layout.addWidget(tl1);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
void combo::addItem(string text);
void combo::addItems(string[] array);
void combo::setItems(string[] array);
void combo::clear();
string combo::currentText();
void combo::setCurrentIndex(int index);
int combo::currentIndex();
currentTextChanged(string text);
currentIndexChanged(int index);
let c1 = form.create_combo();
c1.setItems(["Item 1", "Item 2", "Item 3"]);
let tl2 = form.create_textline();
tl2.setReadOnly(true);
form.connect(c1, "currentTextChanged", function(text){
tl2.setText(c1.currentText());
});
let layout = form.create_vlayout();
layout.addWidget(c1);
layout.addWidget(tl2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
int spin::value();
void spin::setValue(int value);
void spin::setRange(int min, int max);
valueChanged(int);
let c1 = form.create_spin();
c1.setRange(1,10);
let tl2 = form.create_textline();
tl2.setReadOnly(true);
form.connect(c1, "valueChanged", function(value){
tl2.setText(value);
});
let layout = form.create_vlayout();
layout.addWidget(c1);
layout.addWidget(tl2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
bool check::isChecked();
void check::setChecked(bool checked);
stateChanged();
let c1 = form.create_check("Checkbox");
let tl2 = form.create_textline();
tl2.setReadOnly(true);
form.connect(c1, "stateChanged", function(){
if(c1.isChecked())
tl2.setText("Checked");
else
tl2.setText("UnChecked");
});
let layout = form.create_vlayout();
layout.addWidget(c1);
layout.addWidget(tl2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
clicked();
let c1 = form.create_button("Button");
let tl2 = form.create_textline();
tl2.setReadOnly(true);
form.connect(c1, "clicked", function(){
tl2.setText("Clicked!");
});
let layout = form.create_vlayout();
layout.addWidget(c1);
layout.addWidget(tl2);
let dialog = form.create_dialog("");
dialog.setLayout(layout);
dialog.exec()
string[] list::items();
void list::addItem(string item);
void list::addItems(string[] items);
void list::removeItem(int index);
string list::itemText(int index);
void list::setItemText(int index, string text);
void list::clear();
int list::count();
int list::currentRow();
void list::setCurrentRow(int row);
string[] list::selectedRows();
void list::setReadOnly(bool readonly);
currentTextChanged(string currentText);
currentRowChanged(int currentRow);
itemClickedText(string text);
itemDoubleClickedText(string text);
let listw = form.create_list();
listw.addItems(["Item 1", "Item 2", "Item 3"]);
listw.addItem("New");
let text_line = form.create_textline(listw.count())
let text_button = form.create_button("go");
form.connect(text_button, "clicked", function (){
text_line.setText(listw.items());
})
form.connect(listw, "itemClicked", function (text){
text_line.setText(text);
})
let layout = form.create_gridlayout();
layout.addWidget(listw, 0, 0, 1, 2);
layout.addWidget(text_line, 1, 0, 1, 1);
layout.addWidget(text_button, 1, 1, 1, 1);
let dialog = form.create_dialog("");
dialog.setSize(460, 240);
dialog.setLayout(layout);
dialog.exec()
void table::addColumn(string header);
void table::setColumns(string[] headers);
void table::addItems(string[] item);
int table::rowCount();
int table::columnCount();
string table::text(int row, int column);
void table::setText(int row, int column, string text);