You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -114,7 +115,7 @@ Although you instantiate the `QApplication` in `main()`, you can access it throu
114
115
115
116
So that's nice, right?
116
117
A `QApplication` is an object that represents your entire application.
117
-
Not the windows, no buttons...it's the *whole* thing.
118
+
Not the windows, no buttons...it's the *whole* thing.
118
119
119
120
All of those clickable things that we all love to click: those are called **widgets**.
120
121
If you want a useful application, you can't work with just a `QApplication`.
@@ -153,7 +154,7 @@ We then ask Qt to display our text editor window using the `.show()` member func
153
154
So we've got an **application** set up with a text editing **widget**, and we've asked Qt to show it.
154
155
In order to see our application in action, we need to ask it to run using `app.exec()`.
155
156
156
-
{width=80%}
157
+
{width=45%}
157
158
158
159
### Laying out your App
159
160
@@ -169,7 +170,7 @@ To position a bunch of widgets on screen, we use a **layout** widget.
169
170
For example, let's say we want to put a quit button above our text editor (in the same window of course).
170
171
We can use a `QVBoxLayout` to **vertically** (hence the `V`) stack our widgets.
171
172
172
-

173
+
{width=45%}
173
174
174
175
~~~{.cpp .numberLines}
175
176
// #includes left out for the sake of brevity
@@ -205,15 +206,15 @@ A couple of odd things to note:
205
206
206
207
1. On line 7, the `&` tells Qt to set up a keyboard shortcut, \keys{\Alt + q}, that 'presses' the button.[^QShortcut]
207
208
2. You may notice that on lines 6, 7, and 9, we allocate memory with `new` but never call `delete`.
208
-
Unlike normal C++ objects, Qt objects are written so that they clean up their children when they are destructed.
209
+
Unlike typical C++ objects, Qt objects are written so that they clean up their children when they are destructed.
209
210
In this case, our `QTextEdit` and `QPushButton` are added as children to our `QVBoxLayout` object,
210
211
and that layout object is added as a child to the `QWidget` created on line 13.
211
212
This means that as long as we clean up that `QWidget`, all our other objects will get cleaned up automatically!
212
213
(And, since that `QWidget` is a stack-allocated variable, it gets destructed whenever `main()` returns.)[^ObjectTrees]
213
214
214
215
The rest is similar to the last example.
215
216
With layouts, we have the ability to specify how we want our widgets organized on screen.
216
-
In addition to vertical layouts there are horizontal layouts (`QBoxLayout`) and grid layouts (`QGridLayout`) and a handful of others.
217
+
In addition to vertical layouts there are horizontal layouts (`QBoxLayout`), grid layouts (`QGridLayout`), and a handful of others.
217
218
218
219
So, that's dandy...but our quit button doesn't actually do anything!
219
220
To make our buttons work, we need to talk about Signals and Slots.
@@ -329,10 +330,10 @@ The `QMainWindow` has one big ol' widget that goes in the middle of the window
329
330
`setCentralWidget()` is a member function of `QMainWindow` that sets this widget.
330
331
331
332
To create your menus (File, Edit, whatever you want) you need to add them to your `QMainWindow`.
332
-
`menuBar()` is a member function that returns a pointer to the menubar, which you can use to add new menus.
333
-
Similarly, `addToolBar()`is a member function that creates a new toolbars.
333
+
It has a `menuBar()` member function that returns a pointer to the menubar, which you can use to add new menus.
334
+
Similarly, there is an `addToolBar()` member function that creates a new toolbars.
334
335
335
-
Since toolbar buttons and menu items do the same thing (fire an event when clicked), Qt represens them both as `QActions`.
336
+
Since toolbar buttons and menu items do the same thing (fire an event when clicked), Qt represents them both as `QActions`.
336
337
You can add the same `QAction` to both a menu and a toolbar --- so there's less code repetition as well!
337
338
`QAction`s have a `triggered()` signal that is emitted whenever their menu item or button is clicked.
338
339
@@ -557,7 +558,7 @@ We define our signal in the `Notepad` class definition in `notepad.h`:
557
558
voiduseFile(QString fileName);
558
559
~~~
559
560
560
-
This tells Qt that the QButton is capable of hootin' and hollerin' about being clicked.
561
+
This tells Qt that `Notepad` is capable of hootin' and hollerin' about files.
561
562
`signals` is another keyword understood by moc.
562
563
Unlike with slots, you do **not** implement the signal function --- you just have to declare it.
0 commit comments