Skip to content

Commit 4c90bf6

Browse files
committed
Some more stuff
1 parent ac3a08d commit 4c90bf6

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

13-Graphical-User-Interfaces-with-Qt.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
11
# Graphical User Interfaces with Qt
22
<!--
33
TODO
4-
- conclusion / wrap up
5-
- check questions
4+
- screenshots
65
- fill out quick reference
7-
- write further reading section
86
-->
97
## Motivation
108

119
Close your eyes.
1210

1311
Wait, no. Open them! Look around you!
1412

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.
1614
If you do, you should really see a doctor about that.
1715

1816
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:
2018

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}
2223

2324
You lift your hands to sip your coffee, but instead of hands, you see a large mouse cursor.
2425
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.
2526
How do you sip coffee with a cursor?
2627
A piece of paper with the word 'Coffee' written on it suddenly appears over the mug.
2728
You move your ~~hand~~ cursor slightly and the paper vanishes as mysteriously as it appeared.
2829

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*.
3031
Oh. Of course.
32+
3133
You left-click the coffee mug. A dashed outline appears around it.
3234
Obviously.
35+
3336
Maybe right-clicking works? You try, and a board appears below the mug.
3437
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'.
3639
You finally sip your coffee. It's gotten cold. Darn.
3740

3841
Well, time for a change of scenery.
3942
You lift your cursor to the heavens, where another strip of cafeteria tray material hovers.
4043
You select 'View', then 'Outdoors' from the board that appears.
44+
4145
Without warning, you're dumped into the middle of a field.
4246
After the dizziness subsides, you look around.
4347
Where are you?
4448
What is happening?
4549
Why can't things just go back to being text on a screen?
50+
4651
You would scream, but you have no menu entry for that.
4752

4853
### Takeaways
4954

5055
- Experiment with Qt to build Graphical User Interfaces
56+
- Learn a bit about how large libraries and projects are organized
5157
- Appreciate the simplicity of programming Command Line Interface applications.
5258

5359
## Walkthrough
@@ -84,14 +90,14 @@ Once we've added this line, we can just `#include <QtWidgets>` and use all the w
8490
If you already have a `.pro` file, then you can just run `qmake` to generate a `Makefile`.
8591
Then you can run `make` to compile everything together!
8692

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
9096

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
9299

93-
~~~shell
94-
# Just need to run this once to create your Makefile
100+
# Run this once to create your Makefile
95101
$ qmake
96102

97103
# ... 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
147153
So we've got an **application** set up with a text editing **widget**, and we've asked Qt to show it.
148154
In order to see our application in action, we need to ask it to run using `app.exec()`.
149155
150-
![Our first app! Boy howdy. That sure ain't vim.](13/not_vim.png)
156+
![Our first app! Boy howdy. That sure ain't vim.](13/not_vim.png){width=80%}
151157
152158
### Laying out your App
153159
@@ -575,7 +581,8 @@ Next, we need to connect our signal to our freshly--written slot.
575581
We'll do this in `Notepad`'s constructor, right next to `connect()`s for our `QAction`s.
576582
577583
~~~cpp
578-
connect(this, SIGNAL(useFile(QString)), this, SLOT(setTitle(QString)));
584+
connect(this, SIGNAL(useFile(QString)),
585+
this, SLOT(setTitle(QString)));
579586
~~~
580587

581588
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
594601
Here we `emit` the signal named `useFile`; the data that `useFile` should carry along with it is the contents of the `fileName` variable.
595602
Now whenever we open a file or save a file, the filename will appear in the title!
596603
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+
597611
\newpage
598612
## Questions
599613
@@ -614,7 +628,7 @@ Name: `______________________________`
614628
- `qmake` is a utility that manages Qt projects and generates Makefiles automatically.
615629
- The `-project` flag tells Qt to generate a project file (ends in `.pro`) that configures the Makefile.
616630
- `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`
618632
619633
### Signals and Slots
620634
@@ -624,6 +638,11 @@ Name: `______________________________`
624638
625639
## Further Reading
626640
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+
627646
[^QShortcut]: See http://doc.qt.io/qt-5/qshortcut.html#mnemonic for more about this.
628647
[^ObjectTrees]: See http://doc.qt.io/qt-5/objecttrees.html for more about this.
629648
[^string]: Like a regular string, but more Q--ey.

0 commit comments

Comments
 (0)