qt-quick-for-designers-1:all_about_lists
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
qt-quick-for-designers-1:all_about_lists [2013/06/29 05:06] – mithat | qt-quick-for-designers-1:all_about_lists [2013/07/15 22:59] (current) – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== All about lists ====== | ====== All about lists ====== | ||
- | FIXME Simplify and clarify all this after consulting https://qt-project.org/ | + | <WRAP center round important 60%> |
- | + | The following text is taken verbatim from the source slides((See [[qt-quick-for-designers-1: | |
- | * What is a model? | + | </WRAP> |
- | * Models in QtQuick | + | |
- | * ListView | + | |
- | * GridView | + | |
- | * Creating a model dynamically | + | |
===== Models in QtQuick ===== | ===== Models in QtQuick ===== | ||
- | * A **model** is the description of all data about a single item (i.e., a description of a " | + | * What is a model? |
- | * Name | + | |
- | * Surname | + | * Name |
- | * Telephone Number | + | * Surname |
- | * Favorite | + | * Telephone Number |
- | * Icon | + | * Favorite |
- | * Individual items (i.e., " | + | * Icon |
- | * Elements of a '' | + | |
- | * The **'' | + | |
- | <file javascript ListModelExample.qml> | + | |
- | import QtQuick 1.0 | + | |
+ | * Models in QtQuick | ||
+ | * This is how a list item is organized in a QtQuick model. The ListModel element is an array of ListElements | ||
+ | * See example: addon/ | ||
+ | <code javascript> | ||
ListModel { | ListModel { | ||
- | id: listModel | + | ListElement { |
+ | picture: " | ||
+ | name: " | ||
+ | surname: "Nunes Teles" | ||
+ | telephone: "+1 347 715 3354" | ||
+ | favorite: true | ||
+ | icon: " | ||
+ | } | ||
+ | }</ | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: " | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | | ||
- | name: " | ||
- | | ||
- | | ||
- | | ||
- | icon: "" | ||
- | } | ||
- | | ||
- | ===== Model views ===== | + | ===== ListView |
- | * '' | + | * To start creating lists in QtQuick, you must organize your files first. |
+ | * You need, at least, three files | ||
+ | * Single item view | ||
+ | * All the visual elements from each list item and how they appear are in this file | ||
+ | * ListModel | ||
+ | * This is the file presented before, an array of ListElements containing all information from each item | ||
+ | * Main file | ||
+ | * This file will contain the ListView call, the ListModel and the Component for each single item view that will be repeated | ||
- | ==== ListView ==== | + | |
- | * Viewing a '' | + | * See example: addon/ |
- | | + | <code javascript> |
- | * An array of '' | + | ... |
- | * Single item view: | + | Text { |
- | * A file that has specifies how a single item should appear. | + | id: nameTxt |
- | <file javascript | + | font.family: |
- | import QtQuick 1.0 | + | color: "# |
+ | font.pixelSize: | ||
+ | text: "<b>Adriel</ | ||
+ | | ||
+ | anchors.top: | ||
+ | anchors.topMargin: | ||
+ | } | ||
+ | ...</ | ||
- | Item { | + | * ... then you need to make the item flexible enough to accept the variables you need |
- | | + | |
- | | + | <code javascript> |
- | | + | ... |
- | property string intern_name: " | + | property string intern_name |
- | property string intern_surname: " | + | property string intern_surname |
- | property string intern_telephone: | + | property string intern_telephone |
- | | + | ... |
- | | + | } |
+ | Text { | ||
+ | id: nameTxt | ||
+ | font.family: "Univers LT Std" | ||
+ | color: "#c8c8c8" | ||
+ | | ||
+ | text: "< | ||
+ | anchors.left: | ||
+ | anchors.top: | ||
+ | anchors.topMargin: | ||
+ | } | ||
+ | ...</ | ||
+ | * Once you’ve done all of this, now you just need to set the ListView inside the main file | ||
+ | * See example: addon/ | ||
+ | <code javascript> | ||
+ | ListView { | ||
+ | id: listExample | ||
+ | orientation: | ||
+ | model: ListModelExample {} | ||
+ | delegate: itemComponent | ||
+ | } | ||
+ | Component { | ||
+ | id: itemComponent | ||
+ | ListItemExample { | ||
+ | intern_name: | ||
+ | intern_surname: | ||
+ | intern_telephone: | ||
+ | intern_icon: | ||
+ | } | ||
+ | } | ||
+ | ...</ | ||
- | Image { | + | * See example: addon/ |
- | id: icon | + | {{youtube> |
- | | + | |
- | height: 42 | + | |
- | source: if(intern_icon == "" | + | |
- | | + | |
- | Text { | + | ===== GridView ===== |
- | id: nameTxt | + | |
- | font.family: | + | |
- | color: "# | + | |
- | font.pixelSize: | + | |
- | text: "< | + | |
- | anchors.left: | + | |
- | anchors.top: | + | |
- | anchors.topMargin: | + | |
- | } | + | |
- | Text { | + | ===== JavaScript |
- | id: phoneTxt | + | |
- | font.family: | + | |
- | color: "# | + | |
- | font.pixelSize: | + | |
- | text: intern_telephone | + | |
- | anchors.left: | + | |
- | anchors.top: | + | |
- | anchors.topMargin: | + | |
- | } | + | |
- | + | ||
- | Image { | + | |
- | id: favIcon | + | |
- | anchors.left: | + | |
- | anchors.leftMargin: | + | |
- | anchors.top: | + | |
- | anchors.topMargin: | + | |
- | source: if(intern_fav) { return " | + | |
- | } | + | |
- | + | ||
- | }</ | + | |
- | * Main file: | + | |
- | * Contains the '' | + | |
- | <file javascript ListExample.qml> | + | |
- | import QtQuick 1.0 | + | |
- | + | ||
- | Item { | + | |
- | width: 360 | + | |
- | height: 640 | + | |
- | + | ||
- | Image { | + | |
- | id: background | + | |
- | source: " | + | |
- | } | + | |
- | + | ||
- | ListView { | + | |
- | id: listExample | + | |
- | width: 360 | + | |
- | height: 590 | + | |
- | anchors.top: | + | |
- | anchors.topMargin: | + | |
- | anchors.left: | + | |
- | anchors.leftMargin: | + | |
- | orientation: | + | |
- | model: ListModelExample {} | + | |
- | delegate: itemComponent | + | |
- | clip: true | + | |
- | cacheBuffer: | + | |
- | } | + | |
- | + | ||
- | Component { | + | |
- | id: itemComponent | + | |
- | ListItemDelegate { | + | |
- | width: 330 | + | |
- | height: 75 | + | |
- | intern_name: | + | |
- | intern_surname: | + | |
- | intern_telephone: | + | |
- | intern_icon: | + | |
- | intern_fav: model.favorite | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | Image { | + | |
- | id: shadowDetail | + | |
- | source: " | + | |
- | anchors.top: | + | |
- | } | + | |
- | + | ||
- | Image { | + | |
- | id: scrollbar | + | |
- | height: 547 | + | |
- | source: " | + | |
- | anchors.right: | + | |
- | anchors.rightMargin: | + | |
- | anchors.bottom: | + | |
- | anchors.bottomMargin: | + | |
- | } | + | |
- | + | ||
- | Rectangle { | + | |
- | id: scrollknob | + | |
- | width: 2 | + | |
- | radius: 1 | + | |
- | color: "# | + | |
- | anchors.horizontalCenter: | + | |
- | y: (listExample.visibleArea.yPosition * listExample.height) + scrollbar.y | + | |
- | height: ((listExample.height/ | + | |
- | } | + | |
- | + | ||
- | }</ | + | |
- | + | ||
- | ==== GridView | + | |
- | + | ||
- | ===== Javascript | + | |
===== Animating list items ===== | ===== Animating list items ===== | ||
- | + | --------------------------------------------------------------------- | |
- | + | ===== Resources ===== | |
+ | * All source code is subject to this [[copyright header|copyright]]. | ||
qt-quick-for-designers-1/all_about_lists.1372482403.txt.gz · Last modified: 2013/06/29 05:06 by mithat