Skip to content

Commit 7409bd9

Browse files
committed
first bits for a pyqt / qt quick tutorial
1 parent 97148de commit 7409bd9

File tree

5 files changed

+189
-2
lines changed

5 files changed

+189
-2
lines changed

LICENSE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The Creative Commons Attribution Share Alike License 4.0 International (CC-BY-SA)
2+
3+
Copyright (c) 2014 ale rimoldi
4+
5+
You are free to:
6+
7+
Share — copy and redistribute the material in any medium or format
8+
9+
Adapt — remix, transform, and build upon the material
10+
for any purpose, even commercially.
11+
12+
The licensor cannot revoke these freedoms as long as you follow the license terms.
13+
14+
http://creativecommons.org/licenses/by-sa/4.0/

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
python-manual-pyqt-qml
2-
======================
1+
# python-manual-pyqt-qml
32

43
PyQt and QML for desktop development
4+
5+
# Notes and links
6+
7+
Things to read before or during the writing of this book:
8+
9+
- https://qt-project.org/doc/qtcreator-2.7/creator-qml-application.html
10+
- http://qt-project.org/doc/qt-5/qml-advtutorial.html
11+
- [QtDD13 - Python 3 and Qt 5 with QML](https://www.youtube.com/watch?v=2HAFOZ5_Xks)
12+
- [QML for desktop apps](https://www.youtube.com/watch?v=kvWeE3kurEQ)
13+
- [QtDD12 - Effective QML: Best practices for Developing with Qt Quick](https://www.youtube.com/watch?v=m_-8B4acawE)
14+
- [Qt DevDays 2011, Programming with Qt Quick 6/6 - C++ Integration](https://www.youtube.com/watch?v=n3JJZRQG39o)
15+
16+
17+
- Three directories with simply qml examples: https://github.com/pbouda/stuff/blob/master/pyqt-book-examples/pythonqml2/main2.qml
18+
-

content/content.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Introduction
2+
3+
This book is about creating dialogs for Desktop applications with Python 3, PyQt 5 and Qt Quick.
4+
5+
Last year, after having watched [Introduction to Qt Quick Controls in Qt 5.1](https://www.youtube.com/watch?v=_6_F6Kpjd-Q) on YouTube I got very excited and loved the idea of being able to mock dialogs and applications with an harmonius mixture of pseudo JSON and Javascript.
6+
7+
Having being involved in the development of Scribus for the past ten years, I dreamed of designers squeezing their Javascript skills to send us interactive mockups that only required to be rewired to the Scribus code for being integrated into our source code.
8+
While this has yet to happened, this manual is part of the first step to get a new Scripter engine into Scribus that will allow us to integrate in the Scribus UI, Python scripts combined with Qt Quick dialogs.
9+
10+
The path was steeper than I would have thought. On the one side, the move from Qt Quick 1 to Qt Quick 2 has made a lot of tutorials and snippets you can find on the internet slightly outdated: they are familiar enough, so that you get the fealing they might solve your problem, but result in code that fails with error messages that are not helpful enough to bring you on the right path.
11+
12+
- http://stackoverflow.com/questions/15406002/does-python-go-well-with-qml-qt-quick
13+
14+
# Requirements
15+
16+
17+
For enjoying this book you should have:
18+
19+
- A text editor or Qt Creator.
20+
- A computer with Python, PyQt 5 and the Qt Quick 2.X modules installed.
21+
- Basic Python programming skills.
22+
- Some knowledge about what Qt 5 is and what signals and slots are.
23+
24+
25+
TODO: And if you don't already have the required skills, a few links that can help you getting on track
26+
27+
# PyQt 5
28+
29+
- http://pyqt.sourceforge.net/Docs/PyQt5/index.html
30+
31+
# QML and Qt Quick
32+
33+
- [A nice example of QML file](https://github.com/ioriayane/KanmusuMemory/blob/master/qml/KanmusuMemory/TimerSetting.qml)
34+
35+
# Qt Creator or a text editor
36+
37+
38+
39+
# Your first dialog
40+
41+
Create a first dialog, that simply shows a button that you can click to quit:
42+
43+
[%source%main.qml](examples/your-first-dialog/main.qml)
44+
45+
You can preview the dialog with the `qmlviewer` :
46+
47+
$ qmlviewer main.qml
48+
49+
The minimal code that allows you to show the QML window with PyQt:
50+
51+
[%source%dialog.py](examples/your-first-dialog/dialog.py)
52+
53+
$ python dialog.py
54+
55+
56+
# Column and rows
57+
58+
[%source%dialog.py](examples/your-first-dialog/dialog.py)
59+
60+
$ qmlviewer columns.py
61+
62+
# The basics of the dialog items
63+
64+
## Push Buttons
65+
66+
## Groups
67+
68+
## Radio Buttons
69+
70+
## Combo Boxes
71+
72+
- http://qt-project.org/doc/qt-5/qml-qtquick-controls-combobox.html
73+
74+
## Scrollable Lists
75+
76+
This is TableView
77+
78+
- http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html
79+
80+
# Pure Javascript Mockups
81+
82+
## Properties
83+
84+
Further reading:
85+
86+
- http://qt-project.org/doc/qt-5/qtqml-syntax-objectattributes.html
87+
88+
## Models
89+
90+
# Communicating between Python and QML
91+
92+
- http://qt-project.org/doc/qt-5/qtqml-cppintegration-exposecppattributes.html
93+
94+
## Signals from Qt Quick to Python
95+
96+
## Sending values from Python to Qt Quick
97+
98+
## Python Models for Qt Quick
99+
100+
Models have to be passed as an attribute before the `.qml` file is read.
101+
102+
TODO: find out how to use classes as models.
103+
104+
- http://qt-project.org/doc/qt-4.8/qdeclarativemodels.html
105+
- http://qt-project.org/wiki/Filling-and-reading-QML-UI-forms-from-Python
106+
107+
# The standard dialogs
108+
109+
## Message dialogs
110+
111+
## Input dialogs
112+
113+
## File Open dialogs
114+
115+
## File Save dialogs
116+
117+
# Packaging
118+
119+
## Windows
120+
121+
TODO: digest this thread from the PyQt mailing list
122+
123+
> py2exe generated a folder with a lot of dll files, but it didn't include the necessary plugins, copying the contents of the plugins/ directory into the executable's directory seems to have helped (no longer getting a message that qt's windows plugin is missing) but now the application simply crashes as soon as it starts. The error message it displays is an uninformative "program.exe stopped working". I tried to run the executable from the commandline in the hopes of catching some output telling me what I did wrong, but nothing was displayed.
124+
125+
> We're deploying PyQt5 on Windows with the help of `cx_Freeze`, which works really well in our experience. I think we have to copy QtSql plugin files though IIRC. Try it, it's easy.
126+
127+
# Installing Python, PyQt 5 and Qt Quick
128+
129+
TODO: add links to How-tos
130+
TODO: eventually, show how to get it to work in some Linux distributions and promote Virtualbox
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sys
2+
3+
from PyQt5.QtCore import QUrl
4+
from PyQt5.QtGui import QGuiApplication
5+
from PyQt5.QtQml import QQmlApplicationEngine
6+
7+
app = QGuiApplication(sys.argv)
8+
9+
engine = QQmlApplicationEngine("main.qml")
10+
11+
window = engine.rootObjects()[0]
12+
window.show()
13+
14+
sys.exit(app.exec_())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import QtQuick 2.0
2+
import QtQuick.Controls 1.0
3+
4+
ApplicationWindow {
5+
id: root
6+
7+
width: 500
8+
height: 300
9+
title: qsTr("My first dialog")
10+
11+
Button {
12+
text: qsTr("Quit")
13+
onClicked: Qt.quit()
14+
}
15+
}

0 commit comments

Comments
 (0)