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

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
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIICS
 
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 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
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
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
 
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
 
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
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt InternationalizationICS
 

What's hot (20)

QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
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 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
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
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
 
Qt programming-using-cpp
Qt programming-using-cppQt programming-using-cpp
Qt programming-using-cpp
 
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 Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
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
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
IPC with Qt
IPC with QtIPC with Qt
IPC with Qt
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
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 Internationalization
Qt InternationalizationQt Internationalization
Qt Internationalization
 
Qt 5 - C++ and Widgets
Qt 5 - C++ and WidgetsQt 5 - C++ and Widgets
Qt 5 - C++ and Widgets
 
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
 

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
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++Paolo Sereno
 
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 (19)

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
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++
 
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
 
Qt quick (qml)
Qt quick (qml)Qt quick (qml)
Qt quick (qml)
 

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

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...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
 

More from ICS (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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
 

Recently uploaded

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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.