Qt for beginners Exercise 1 basis: Difference between revisions
No edit summary |
(No difference)
|
Revision as of 16:47, 14 January 2015
Qt for beginners — Exercise 1 : basis
<<< Signals and slots 2 | Summary | Finding information in the documentation >>>
Note: Unfortunately, the images are no longer available. See the official Getting Started with Qt Widgets [qt.io] page for an alternative tutorial.
Widgets
Radio button is a standard GUI component. It is often used to make a unique choice from a list. In Qt, the QRadioButton is used to create radio buttons.
Thanks to a nice heritance, a QRadioButton just behaves like a QPushButton. All properties of the QPushButton are also the same in the QRadioButton, and everything that was learnt in the second chapter can be reused here
- text
- icon
- tooltip
- …
By default, QRadioButtons are not grouped, so many of them can be checked at the same time. In order to have the “exclusive” behaviour of many radio buttons, we need to use QButtonGroup. This class can be used like this
What we want is to create a menu picker. In a window, a list of yummy plates should be displayed with radio buttons, and a push button that is used to select the chosen plate should be displayed.
Obviously, nothing will happen (now) when the buttons are clicked.
Signals and slots
Here is an example about signals and slots. We are going to write an application with two buttons. The first button should display information about Qt, like in the following dialog
We provide you the following code to complete :
In order to display the information about Qt, you should use the following method
You can also add icons on the buttons, or resize them. Obviously, the “Quit” button should be more important, so why not make it bigger ?
The answers can be found here. But we really recommend you to try and figure it out by yourself how to solve these exercises.
<<< Signals and slots 2 | Summary | Finding information in the documentation >>>