1
1
# Graphical User Interfaces with Qt
2
2
<!--
3
3
TODO
4
- - conclusion / wrap up
5
- - check questions
4
+ - screenshots
6
5
- fill out quick reference
7
- - write further reading section
8
6
-->
9
7
## Motivation
10
8
11
9
Close your eyes.
12
10
13
11
Wait, no. Open them! Look around you!
14
12
15
- Unless you're a 1337 cyber hacker, you probably don't see just characters in terminals.
13
+ Unless you're a 1337 cyber hacker, you probably don't see just text in terminals.
16
14
If you do, you should really see a doctor about that.
17
15
18
16
Ok, this next part might be a little weird, but trust us, it's necessary for your understanding.
19
- You may feel some slight discomfort as you read the next line.
17
+ You may feel some slight discomfort as you read the next bit:
20
18
21
- ** INSERT SOMETHING "HORRIFYING" HERE** (maybe Zalgo text?)
19
+ \begin{figure}
20
+ \centering
21
+ \includegraphics[ width=0.5\textwidth] {13/zalgo.png}
22
+ \end{figure}
22
23
23
24
You lift your hands to sip your coffee, but instead of hands, you see a large mouse cursor.
24
25
Disturbed but undeterred (coffee is important, after all), you move your cursor towards your mug, but you pause once the cursor is on the mug.
25
26
How do you sip coffee with a cursor?
26
27
A piece of paper with the word 'Coffee' written on it suddenly appears over the mug.
27
28
You move your ~~ hand~~ cursor slightly and the paper vanishes as mysteriously as it appeared.
28
29
29
- You take a moment to do some introspection, and discover you know how to * left-click* and * right-click* .
30
+ You take a moment for some introspection, and discover you know how to * left-click* and * right-click* .
30
31
Oh. Of course.
32
+
31
33
You left-click the coffee mug. A dashed outline appears around it.
32
34
Obviously.
35
+
33
36
Maybe right-clicking works? You try, and a board appears below the mug.
34
37
It looks like it's made out of a cafeteria tray.
35
- A list of words is written on it: 'Tip Over', 'Hurl through Window', 'Upend', ... and, at last, 'Sip'.
38
+ A list of words is written on it: 'Tip Over', 'Hurl through Window', 'Upend'... and, at last, 'Sip'.
36
39
You finally sip your coffee. It's gotten cold. Darn.
37
40
38
41
Well, time for a change of scenery.
39
42
You lift your cursor to the heavens, where another strip of cafeteria tray material hovers.
40
43
You select 'View', then 'Outdoors' from the board that appears.
44
+
41
45
Without warning, you're dumped into the middle of a field.
42
46
After the dizziness subsides, you look around.
43
47
Where are you?
44
48
What is happening?
45
49
Why can't things just go back to being text on a screen?
50
+
46
51
You would scream, but you have no menu entry for that.
47
52
48
53
### Takeaways
49
54
50
55
- Experiment with Qt to build Graphical User Interfaces
56
+ - Learn a bit about how large libraries and projects are organized
51
57
- Appreciate the simplicity of programming Command Line Interface applications.
52
58
53
59
## Walkthrough
@@ -84,14 +90,14 @@ Once we've added this line, we can just `#include <QtWidgets>` and use all the w
84
90
If you already have a ` .pro ` file, then you can just run ` qmake ` to generate a ` Makefile ` .
85
91
Then you can run ` make ` to compile everything together!
86
92
87
- Lucky you!
88
- In this lab, your projects will come with pre-configured ` .pro ` files.
89
- So, you don't have to worry about generating those.
93
+ ~~~ shell
94
+ # Run this to create a project file
95
+ $ qmake -project
90
96
91
- For this lab, you just need to run ` qmake ` one time to generate a ` Makefile ` , and ` make ` whenever you want to build.
97
+ # Edit the file to enable widgets
98
+ $ echo " QT += widgets" >> project_name.pro
92
99
93
- ~~~ shell
94
- # Just need to run this once to create your Makefile
100
+ # Run this once to create your Makefile
95
101
$ qmake
96
102
97
103
# ... then this whenever you want to recompile
@@ -147,7 +153,7 @@ We then ask Qt to display our text editor window using the `.show()` member func
147
153
So we've got an **application** set up with a text editing **widget**, and we've asked Qt to show it.
148
154
In order to see our application in action, we need to ask it to run using `app.exec()`.
149
155
150
- 
156
+ {width=80%}
151
157
152
158
### Laying out your App
153
159
@@ -575,7 +581,8 @@ Next, we need to connect our signal to our freshly--written slot.
575
581
We'll do this in `Notepad`'s constructor, right next to `connect()`s for our `QAction`s.
576
582
577
583
~~~cpp
578
- connect(this, SIGNAL(useFile(QString)), this, SLOT(setTitle(QString)));
584
+ connect(this, SIGNAL(useFile(QString)),
585
+ this, SLOT(setTitle(QString)));
579
586
~~~
580
587
581
588
When connecting signals and slots that carry data, you must specify the types of the parameters of the signal and slot.
@@ -594,6 +601,13 @@ So, in both `open()` and `save()`, immediately after the `file.close()` line, we
594
601
Here we `emit` the signal named `useFile`; the data that `useFile` should carry along with it is the contents of the `fileName` variable.
595
602
Now whenever we open a file or save a file, the filename will appear in the title!
596
603
604
+ By now, you know the basics of arranging widgets on screen and event-driven programming with signals and slots.
605
+ There are a lot of different widgets out there!
606
+ If you want to build more featureful GUI programs, you should definitely have a look through what Qt has to offer.
607
+ Also, have a look through the documentation on the widgets we've used in this chapter.
608
+ They sport a lot of features we don't have space to talk about here.
609
+ Qt's documentation is a little daunting, but quite detailed!
610
+
597
611
\newpage
598
612
## Questions
599
613
@@ -614,7 +628,7 @@ Name: `______________________________`
614
628
- `qmake` is a utility that manages Qt projects and generates Makefiles automatically.
615
629
- The `-project` flag tells Qt to generate a project file (ends in `.pro`) that configures the Makefile.
616
630
- `qmake` will generate a Makefile
617
- - If you already have a `.pro` file, all you have to do to build a Qt project: run `qmake` then `make`
631
+ - If you already have a `.pro` file, all you have to do to build a Qt project: run `qmake`, then `make`
618
632
619
633
### Signals and Slots
620
634
@@ -624,6 +638,11 @@ Name: `______________________________`
624
638
625
639
## Further Reading
626
640
641
+ - [A list of all Qt classes](http://doc.qt.io/qt-5/classes.html), with links to documentation for each
642
+ - [Qt Examples and Tutorials](http://doc.qt.io/qt-5/qtexamplesandtutorials.html)
643
+ - [`qmake` documentation](http://doc.qt.io/qt-5/qmake-manual.html)
644
+ - [Qt Development Tools](http://doc.qt.io/qt-5/topics-app-development.html), including an IDE!
645
+
627
646
[^QShortcut]: See http://doc.qt.io/qt-5/qshortcut.html#mnemonic for more about this.
628
647
[^ObjectTrees]: See http://doc.qt.io/qt-5/objecttrees.html for more about this.
629
648
[^string]: Like a regular string, but more Q--ey.
0 commit comments