SlideShare a Scribd company logo
1 of 38
Download to read offline
Qt Quick Best Practices
Part 2
Langston Ball
ICS Consulting Engineer
ICS, Inc.
Agenda
• Creating New Item
• State and Transitions
• Dynamic Creation of Items
Creating New Items
Extending Items
• Any instance of a QML item is effectively a
subclass
• Add member properties
• Add member functions
• Add signals
• There is no reason to add signals to an instance
Extending Items
Rectangle{
Text {
id: label
property int count: 1
text: “Count = ” + count
function incrementCount() {
count = count+1
}
}
Timer {
running: true
onTriggered: label.incrementCount()
}
}
Property Types
• Properties can be almost any type
• Basic: int, real, string, date, time, point
• Copies are stored
• Any valid QML type: Rectangle, Text
• These are actually pointers
• The “var” type is equivalent to Qvariant
• Use explicit types as much as you can
• They are faster
Property Types
Rectangle{
id: button
property int anInt: 1
property real aDouble: 50.5
property bool aBool: false
property string aString: “”
property var anything: 50.5
property list<point> points: [ Qt.point(0,0), Qt.point(100,100) ]
}
Dividing Code Into Components
• Often a devs to put too much code in one
QML file
• Common issue for all programming languages
• QML makes it easy to componentize your code
• Component refers to an item that can be
instanced multiple times
Creating New Items
• Simply create a new .qml file
• Type is named after the filename
• Must begin with a capital letter
• Implement
• Properties
• Signals
• Functions
Inline Button Code
Rectangle{ // Main.qml
id: toplevel
color: “black”
Rectangle {
id: button
width: 100; height: 50
color: “blue”
Text {
text: “Click Me”
}
MouseArea {
anchors.fill: parent
onPressedChanged: button.color = (pressed) ? “red” : “blue”
onClicked: toplevel.color = “white”
}
}
}
Componentized Button
Rectangle{ // Main.qml
id: toplevel
color: “black”
Button {
text: “Click Me”
onClicked: toplevel.color = “white”
}
}
Componentized Button
Rectangle{ // Button.qml
id: button
property alias text: label.text
signal clicked()
color: “blue”
width: 100; height: 50
Text {
id: label
anchors.centerIn: parent
}
MouseArea{
id: ma
anchors.fill: parent
onClicked: button.clicked()
}
}
Alias Properties
• Proxies properties to child items
• Allows hiding of implementation details
• Saves memory and binding recalculations
Property Scope
• Public Scope
• All public properties of the root item
• Custom properties defined on the root item
• Private Scope
• All child items and their properties
Public Members
Rectangle{ // Button.qml
id: button
property alias text: label.text
signal clicked()
color: “blue”
Text {
id: label
anchors.centerIn: parent
}
MouseArea{
id: ma
anchors.fill: parent
onClicked: button.clicked()
}
}
Private Members
Rectangle{ // Button.qml
id: button
property alias text: label.text
signal clicked()
color: “blue”
Text {
id: label
anchors.centerIn: parent
}
MouseArea{
id: ma
anchors.fill: parent
onClicked: button.clicked()
}
}
Private Properties
Rectangle { // Button.qml
id: button
property alias text: label.text
signal clicked()
QtObject {
id: internal
property int centerX: button.width()/2
}
Text {
x: internal.centerX
}
}
Avoid Inheriting Public Members
// Inherit from the basic Item type and hide everything else
Item { // Button.qml
id: button
property alias text: label.text
signal clicked()
Rectangle {
id: background
color: “blue”
}
Text {
id: label
anchors.centerIn: parent
}
...
}
States and Transitions
States
• State Machines can make your code “more
declarative”
• A basic state machine is built into every Item
• No parallel states or state history
States
• Every Item has a states property
• States contain
• Name
• When Clause
• List of PropertyChanges{} objects
Setting States
• Item can be set to a give state two ways
• 1) “state” property is set to the name of the
State
• item.state = “Pressed”
• 2) The when clause of the State is true
• When clauses must be mutually exclusive
• They are evaluated in creation order
Button States
Item {
Rectangle { id: bkg; color: “blue” }
MouseArea { id: ma }
states: [
State {
name: “Pressed”
when: ma.pressed
PropertyChanges { target: bkg; color: “red” }
},
State {
name: “Disabled”
when: !(ma.enabled)
PropertyChanges { target: bkg; color: “grey” }
}
]
}
Default State
• The initial bindings are the “Default State”
• The name of the default state is “”
• Default state is in effect when
• No when clauses are satisfied
• “state” property is set to “”
Properties When in a State
• The bindings of a QML document is defined
as
• The default state bindings
• Overlaid with PropertyChanges from the current
state
• This will save you a ton of typing
• States do not need to be unwound
• Set common properties in the default state
• Avoids writing duplicate PropertyChanges
Transitions
• Run animations on a state change
• Control how properties will change
• Qt will automatically interpolate values
• Control in which order properties change
Transitions
[ ... ]
transitions: [
Transition {
from: “”; to: “Pressed”
PropertyAnimation { target: bkg
properties: “color”
duration: 500
},
Transition {
from: “*”; to: “Disabled”
PropertyAnimation { target: bkg
properties: “color”
duration: 250
}
]
[ ... ]
Transition Defaults
• Transition{} defaults to
• from: “*”; to: “*”
• That Transition will apply to all state changes
• PropertyAnimation
• When a target is not specified
• That animation will apply to all items
Button Transition
Item {
Rectangle { id: bkg; color: “blue” }
MouseArea { id: ma }
states: [
State { name: “Pressed”; when: ma.pressed
PropertyChanges { target: bkg; color: “red” }
},
State { name: “Disabled”; when: !(ma.enabled)
PropertyChanges { target: bkg; color: “grey” }
}
]
transitions: [
Transition {
PropertyAnimation { properties: “color”; duration: 500 }
}
]
}
Dynamic Creation of Items
Creating Items Dynamically
• Procedural Way
• Component createObject(parent, bindings)
function
• Declarative Way
• Loader Item
• Repeater Item
• ListView / GridView Items
Procedural Creation
Item {
id: screen
property SettingDialog dialog: undefined
Button {
text: “Settings...”
onClicked: {
var component = Qt.createComponent(“SettingsDialog.qml”)
screen.dialog = component.createObject(screen,
{ anchors.centerIn: screen
})
screen.dialog.close.connect(screen.destroySettingsDialog)
}
function destroySettingsDialog()
{
screen.dialog.destroy()
screen.dialog = undefined
}
}
Procedural / Declarative Creation
Item {
id: screen
Button {
text: “Settings...”
onClicked: {
dialogComponent.createObject(screen)
}
Component {
id: dialogComponent
SettingsDialog {
anchors.centerIn: parent
onClose: destroy()
}
}
}
Declarative Creation
Item {
Button {
text: “Settings...”
onClicked: loader.sourceComponent = dialogComponent
Loader {
id: loader
anchors.fill: parent
}
Component {
id: dialogComponent
SettingsDialog {
anchors.centerIn: parent
onClose: loader.sourceComponent = undefined
}
}
}
Creating Multiple Items
Item {
width: 400; height: 400
color: “black”
Grid {
x: 5; y:5
rows: 5; columns: 5
Repeater {
model: 24
Rectangle {
width: 70; height: 70
color: “lightgreen”
}
}
}
}
Creating Multiple Items
Item {
width: 400; height: 400
color: “black”
Grid {
x: 5; y:5
rows: 5; columns: 5
Repeater {
model: 24
Rectangle {
width: 70; height: 70
color: “lightgreen”
Text {
anchors.centerIn: parent
text: index
}
}
}
}
}
Repeater
• Repeaters can use all type of data models
• ListModel
• JSON Data
• property list<type>
• QList<QObject*>
• QAbstractItemModel
• Model data is accessed via attached
properties
Thank You!
Part III: July 23rd, 2015
Http://www.ics.com/webinars
Langston Ball
ICS Consulting Engineer
ICS, Inc.

More Related Content

What's hot

Qt test framework
Qt test frameworkQt test framework
Qt test frameworkICS
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3ICS
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickICS
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6ICS
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key conceptsICS
 
Lessons Learned from Building 100+ C++/Qt/QML Devices
Lessons Learned from Building 100+ C++/Qt/QML DevicesLessons Learned from Building 100+ C++/Qt/QML Devices
Lessons Learned from Building 100+ C++/Qt/QML DevicesICS
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt InternationalizationICS
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals ThreadsNeera Mital
 
Unit testing with Qt test
Unit testing with Qt testUnit testing with Qt test
Unit testing with Qt testDavide Coppola
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentICS
 

What's hot (20)

Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
UI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QMLUI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QML
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
Qt programming-using-cpp
Qt programming-using-cppQt programming-using-cpp
Qt programming-using-cpp
 
Lessons Learned from Building 100+ C++/Qt/QML Devices
Lessons Learned from Building 100+ C++/Qt/QML DevicesLessons Learned from Building 100+ C++/Qt/QML Devices
Lessons Learned from Building 100+ C++/Qt/QML Devices
 
Qt Application Programming with C++ - Part 1
Qt Application Programming with C++ - Part 1Qt Application Programming with C++ - Part 1
Qt Application Programming with C++ - Part 1
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt Internationalization
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
Unit testing with Qt test
Unit testing with Qt testUnit testing with Qt test
Unit testing with Qt test
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
Qt for beginners
Qt for beginnersQt for beginners
Qt for beginners
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 

Viewers also liked

Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Pasi Kellokoski
 
[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project
[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project
[Webinar] 10 Keys to Ensuring Success for Your Next Qt ProjectICS
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UIOpenBossa
 
Qt for beginners part 5 ask the experts
Qt for beginners part 5   ask the expertsQt for beginners part 5   ask the experts
Qt for beginners part 5 ask the expertsICS
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing moreICS
 
Qt for beginners part 2 widgets
Qt for beginners part 2   widgetsQt for beginners part 2   widgets
Qt for beginners part 2 widgetsICS
 
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with QtICS
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangeBurkhard Stubert
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++Paolo Sereno
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? ICS
 
Efficient Graphics with Qt
Efficient Graphics with QtEfficient Graphics with Qt
Efficient Graphics with QtAriya Hidayat
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization SoftwareCase Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Softwareaccount inactive
 
State of the Art OpenGL and Qt
State of the Art OpenGL and QtState of the Art OpenGL and Qt
State of the Art OpenGL and QtICS
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtICS
 
What's unique to Qt
What's unique to QtWhat's unique to Qt
What's unique to QtYikei Lu
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Nativeaccount inactive
 

Viewers also liked (20)

Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7
 
[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project
[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project
[Webinar] 10 Keys to Ensuring Success for Your Next Qt Project
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UI
 
Qt for beginners part 5 ask the experts
Qt for beginners part 5   ask the expertsQt for beginners part 5   ask the experts
Qt for beginners part 5 ask the experts
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing more
 
Qt for beginners part 2 widgets
Qt for beginners part 2   widgetsQt for beginners part 2   widgets
Qt for beginners part 2 widgets
 
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
 
Introduction to Qt
Introduction to QtIntroduction to Qt
Introduction to Qt
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
GMock framework
GMock frameworkGMock framework
GMock framework
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
Efficient Graphics with Qt
Efficient Graphics with QtEfficient Graphics with Qt
Efficient Graphics with Qt
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization SoftwareCase Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
 
State of the Art OpenGL and Qt
State of the Art OpenGL and QtState of the Art OpenGL and Qt
State of the Art OpenGL and Qt
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
What's unique to Qt
What's unique to QtWhat's unique to Qt
What's unique to Qt
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
 

Similar to Best Practices in Qt Quick/QML - Part II

Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Janel Heilbrunn
 
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2ICS
 
Ubuntu app development
Ubuntu app development Ubuntu app development
Ubuntu app development Xiaoguo Liu
 
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...Rebekka Aalbers-de Jong
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom eventBunlong Van
 
QML\Qt Quick на практике
QML\Qt Quick на практикеQML\Qt Quick на практике
QML\Qt Quick на практикеPlatonov Sergey
 
Session iii(server controls)
Session iii(server controls)Session iii(server controls)
Session iii(server controls)Shrijan Tiwari
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Thinkful
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろうUnity Technologies Japan K.K.
 
Having fun power apps components HandsOn - Power User Days Belgium 2019
Having fun power apps components HandsOn - Power User Days Belgium 2019Having fun power apps components HandsOn - Power User Days Belgium 2019
Having fun power apps components HandsOn - Power User Days Belgium 2019Rebekka Aalbers-de Jong
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & AnimationNguyen Tuan
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 
WEB PROGRAMMING ANALYSIS
WEB PROGRAMMING ANALYSISWEB PROGRAMMING ANALYSIS
WEB PROGRAMMING ANALYSISsweetysweety8
 
Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013Fons Sonnemans
 

Similar to Best Practices in Qt Quick/QML - Part II (20)

Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2
 
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2
 
Ubuntu app development
Ubuntu app development Ubuntu app development
Ubuntu app development
 
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
QML\Qt Quick на практике
QML\Qt Quick на практикеQML\Qt Quick на практике
QML\Qt Quick на практике
 
Session iii(server controls)
Session iii(server controls)Session iii(server controls)
Session iii(server controls)
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
 
Having fun power apps components HandsOn - Power User Days Belgium 2019
Having fun power apps components HandsOn - Power User Days Belgium 2019Having fun power apps components HandsOn - Power User Days Belgium 2019
Having fun power apps components HandsOn - Power User Days Belgium 2019
 
Session 5#
Session 5#Session 5#
Session 5#
 
Jquery 3
Jquery 3Jquery 3
Jquery 3
 
JQuery
JQueryJQuery
JQuery
 
Java Script Basics
Java Script BasicsJava Script Basics
Java Script Basics
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 
Lightning chess
Lightning chessLightning chess
Lightning chess
 
WEB PROGRAMMING ANALYSIS
WEB PROGRAMMING ANALYSISWEB PROGRAMMING ANALYSIS
WEB PROGRAMMING ANALYSIS
 
Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013
 

More from ICS

Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...ICS
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarICS
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfICS
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfICS
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfICS
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfICS
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up ICS
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfICS
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesICS
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureICS
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt UsersICS
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...ICS
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer FrameworkICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyICS
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoTICS
 
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdfSoftware Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdfICS
 

More from ICS (20)

Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdf
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdf
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoT
 
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdfSoftware Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdf
 

Recently uploaded

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Best Practices in Qt Quick/QML - Part II

  • 1. Qt Quick Best Practices Part 2 Langston Ball ICS Consulting Engineer ICS, Inc.
  • 2. Agenda • Creating New Item • State and Transitions • Dynamic Creation of Items
  • 4. Extending Items • Any instance of a QML item is effectively a subclass • Add member properties • Add member functions • Add signals • There is no reason to add signals to an instance
  • 5. Extending Items Rectangle{ Text { id: label property int count: 1 text: “Count = ” + count function incrementCount() { count = count+1 } } Timer { running: true onTriggered: label.incrementCount() } }
  • 6. Property Types • Properties can be almost any type • Basic: int, real, string, date, time, point • Copies are stored • Any valid QML type: Rectangle, Text • These are actually pointers • The “var” type is equivalent to Qvariant • Use explicit types as much as you can • They are faster
  • 7. Property Types Rectangle{ id: button property int anInt: 1 property real aDouble: 50.5 property bool aBool: false property string aString: “” property var anything: 50.5 property list<point> points: [ Qt.point(0,0), Qt.point(100,100) ] }
  • 8. Dividing Code Into Components • Often a devs to put too much code in one QML file • Common issue for all programming languages • QML makes it easy to componentize your code • Component refers to an item that can be instanced multiple times
  • 9. Creating New Items • Simply create a new .qml file • Type is named after the filename • Must begin with a capital letter • Implement • Properties • Signals • Functions
  • 10. Inline Button Code Rectangle{ // Main.qml id: toplevel color: “black” Rectangle { id: button width: 100; height: 50 color: “blue” Text { text: “Click Me” } MouseArea { anchors.fill: parent onPressedChanged: button.color = (pressed) ? “red” : “blue” onClicked: toplevel.color = “white” } } }
  • 11. Componentized Button Rectangle{ // Main.qml id: toplevel color: “black” Button { text: “Click Me” onClicked: toplevel.color = “white” } }
  • 12. Componentized Button Rectangle{ // Button.qml id: button property alias text: label.text signal clicked() color: “blue” width: 100; height: 50 Text { id: label anchors.centerIn: parent } MouseArea{ id: ma anchors.fill: parent onClicked: button.clicked() } }
  • 13. Alias Properties • Proxies properties to child items • Allows hiding of implementation details • Saves memory and binding recalculations
  • 14. Property Scope • Public Scope • All public properties of the root item • Custom properties defined on the root item • Private Scope • All child items and their properties
  • 15. Public Members Rectangle{ // Button.qml id: button property alias text: label.text signal clicked() color: “blue” Text { id: label anchors.centerIn: parent } MouseArea{ id: ma anchors.fill: parent onClicked: button.clicked() } }
  • 16. Private Members Rectangle{ // Button.qml id: button property alias text: label.text signal clicked() color: “blue” Text { id: label anchors.centerIn: parent } MouseArea{ id: ma anchors.fill: parent onClicked: button.clicked() } }
  • 17. Private Properties Rectangle { // Button.qml id: button property alias text: label.text signal clicked() QtObject { id: internal property int centerX: button.width()/2 } Text { x: internal.centerX } }
  • 18. Avoid Inheriting Public Members // Inherit from the basic Item type and hide everything else Item { // Button.qml id: button property alias text: label.text signal clicked() Rectangle { id: background color: “blue” } Text { id: label anchors.centerIn: parent } ... }
  • 20. States • State Machines can make your code “more declarative” • A basic state machine is built into every Item • No parallel states or state history
  • 21. States • Every Item has a states property • States contain • Name • When Clause • List of PropertyChanges{} objects
  • 22. Setting States • Item can be set to a give state two ways • 1) “state” property is set to the name of the State • item.state = “Pressed” • 2) The when clause of the State is true • When clauses must be mutually exclusive • They are evaluated in creation order
  • 23. Button States Item { Rectangle { id: bkg; color: “blue” } MouseArea { id: ma } states: [ State { name: “Pressed” when: ma.pressed PropertyChanges { target: bkg; color: “red” } }, State { name: “Disabled” when: !(ma.enabled) PropertyChanges { target: bkg; color: “grey” } } ] }
  • 24. Default State • The initial bindings are the “Default State” • The name of the default state is “” • Default state is in effect when • No when clauses are satisfied • “state” property is set to “”
  • 25. Properties When in a State • The bindings of a QML document is defined as • The default state bindings • Overlaid with PropertyChanges from the current state • This will save you a ton of typing • States do not need to be unwound • Set common properties in the default state • Avoids writing duplicate PropertyChanges
  • 26. Transitions • Run animations on a state change • Control how properties will change • Qt will automatically interpolate values • Control in which order properties change
  • 27. Transitions [ ... ] transitions: [ Transition { from: “”; to: “Pressed” PropertyAnimation { target: bkg properties: “color” duration: 500 }, Transition { from: “*”; to: “Disabled” PropertyAnimation { target: bkg properties: “color” duration: 250 } ] [ ... ]
  • 28. Transition Defaults • Transition{} defaults to • from: “*”; to: “*” • That Transition will apply to all state changes • PropertyAnimation • When a target is not specified • That animation will apply to all items
  • 29. Button Transition Item { Rectangle { id: bkg; color: “blue” } MouseArea { id: ma } states: [ State { name: “Pressed”; when: ma.pressed PropertyChanges { target: bkg; color: “red” } }, State { name: “Disabled”; when: !(ma.enabled) PropertyChanges { target: bkg; color: “grey” } } ] transitions: [ Transition { PropertyAnimation { properties: “color”; duration: 500 } } ] }
  • 31. Creating Items Dynamically • Procedural Way • Component createObject(parent, bindings) function • Declarative Way • Loader Item • Repeater Item • ListView / GridView Items
  • 32. Procedural Creation Item { id: screen property SettingDialog dialog: undefined Button { text: “Settings...” onClicked: { var component = Qt.createComponent(“SettingsDialog.qml”) screen.dialog = component.createObject(screen, { anchors.centerIn: screen }) screen.dialog.close.connect(screen.destroySettingsDialog) } function destroySettingsDialog() { screen.dialog.destroy() screen.dialog = undefined } }
  • 33. Procedural / Declarative Creation Item { id: screen Button { text: “Settings...” onClicked: { dialogComponent.createObject(screen) } Component { id: dialogComponent SettingsDialog { anchors.centerIn: parent onClose: destroy() } } }
  • 34. Declarative Creation Item { Button { text: “Settings...” onClicked: loader.sourceComponent = dialogComponent Loader { id: loader anchors.fill: parent } Component { id: dialogComponent SettingsDialog { anchors.centerIn: parent onClose: loader.sourceComponent = undefined } } }
  • 35. Creating Multiple Items Item { width: 400; height: 400 color: “black” Grid { x: 5; y:5 rows: 5; columns: 5 Repeater { model: 24 Rectangle { width: 70; height: 70 color: “lightgreen” } } } }
  • 36. Creating Multiple Items Item { width: 400; height: 400 color: “black” Grid { x: 5; y:5 rows: 5; columns: 5 Repeater { model: 24 Rectangle { width: 70; height: 70 color: “lightgreen” Text { anchors.centerIn: parent text: index } } } } }
  • 37. Repeater • Repeaters can use all type of data models • ListModel • JSON Data • property list<type> • QList<QObject*> • QAbstractItemModel • Model data is accessed via attached properties
  • 38. Thank You! Part III: July 23rd, 2015 Http://www.ics.com/webinars Langston Ball ICS Consulting Engineer ICS, Inc.