-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(example): example script to get/set data
Add an example of use for script dialog with a widget Fixes #28
- Loading branch information
Showing
3 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Example script with all the different widgets managed by ScriptDialog showing how to set/get data | ||
|
||
import Script 1.0 | ||
|
||
ScriptDialog { | ||
id: root | ||
|
||
// Function called at startup, once the dialog is setup | ||
function init() { | ||
// Initializing widget data | ||
data.lineEdit = "Initialization text" | ||
// Define checkBox as unchecked and radioButton as checked | ||
data.checkBox = false | ||
data.radioButton = true | ||
data.spinBox = 1 | ||
data.doubleSpinBox = 4.2 | ||
// Defined the possible choices for the comboBoxfine | ||
data.comboBoxModel = ["1", "2", "3"] | ||
data.comboBox = "2" | ||
} | ||
|
||
function showData() { | ||
Message.log("OK button is clicked") | ||
Message.log("LineEdit data: " + data.lineEdit) | ||
Message.log("CheckBox data: " + data.checkBox) | ||
Message.log("RadioButton data: " + data.radioButton) | ||
Message.log("SpinBox data: " + data.spinBox) | ||
Message.log("DoubleSpinBox data: " + data.doubleSpinBox) | ||
Message.log("ComboBox data: " + data.comboBox) | ||
} | ||
|
||
// Function called when the user click on the OK button | ||
onAccepted: { | ||
// Logging the state of each widget when OK is clicked | ||
showData(); | ||
} | ||
|
||
// Function called when the user click on the Cancel button | ||
onRejected: { | ||
// Logging when the Cancel button is clicked | ||
Message.log("Cancel button is clicked") | ||
} | ||
|
||
// Function called when a button is clicked | ||
onClicked:(name)=>{ | ||
if (name == "pushButton"){ | ||
Message.log("PushButton is clicked") | ||
} | ||
else if (name == "toolButton"){ | ||
Message.log("ToolButton is clicked") | ||
} | ||
} | ||
// Function to automatically test the script, useful for automated testing | ||
// It runs the script without user interaction | ||
function test() { | ||
showData(); | ||
close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Form</class> | ||
<widget class="QWidget" name="Form"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>407</width> | ||
<height>374</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="label_4"> | ||
<property name="text"> | ||
<string>pushButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QPushButton" name="pushButton"> | ||
<property name="text"> | ||
<string>PushButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>lineEdit:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QLineEdit" name="lineEdit"> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="0"> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>checkBox</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="1"> | ||
<widget class="QCheckBox" name="checkBox"> | ||
<property name="text"> | ||
<string>CheckBox</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="4" column="0"> | ||
<widget class="QLabel" name="label_8"> | ||
<property name="text"> | ||
<string>radioButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="4" column="1"> | ||
<widget class="QRadioButton" name="radioButton"> | ||
<property name="text"> | ||
<string>RadioButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="5" column="0"> | ||
<widget class="QLabel" name="label_7"> | ||
<property name="text"> | ||
<string>spinBox</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="5" column="1"> | ||
<widget class="QSpinBox" name="spinBox"/> | ||
</item> | ||
<item row="6" column="0"> | ||
<widget class="QLabel" name="label_6"> | ||
<property name="text"> | ||
<string>doubleSpinBox</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="6" column="1"> | ||
<widget class="QDoubleSpinBox" name="doubleSpinBox"/> | ||
</item> | ||
<item row="7" column="0"> | ||
<widget class="QLabel" name="label_5"> | ||
<property name="text"> | ||
<string>comboBox</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="7" column="1"> | ||
<widget class="QComboBox" name="comboBox"/> | ||
</item> | ||
<item row="8" column="1"> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>249</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item row="12" column="0"> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="text"> | ||
<string>dialogButtonBox</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="12" column="1"> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QToolButton" name="toolButton"> | ||
<property name="enabled"> | ||
<bool>true</bool> | ||
</property> | ||
<property name="text"> | ||
<string>ToolButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="label_9"> | ||
<property name="text"> | ||
<string>toolButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters