Chapter 3. Tutorial: Adding Functionality To A Dialog By Subclassing

Table of Contents
Continuing Work On An Already Existing Dialog
Adding Functionality To The Push Buttons
Initializing The State Of Widgets In The Form
Connecting Widgets To Each Other

In this chapter, we will build on the pizza entry form presented in the last chapter and augment it. You will learn how to continue work on an already existing dialog and how to add functionality to the dialog classes that Qt Designer creates for you.

Continuing Work On An Already Existing Dialog

Once you have run your application, you might notice that your dialog still needs work. This is no problem at all. All you have to do is start Qt Designer again (in case you have shut it down in the meantime) and load the .ui file via the menu entry File/Open or the load button on the toolbar (see Figure 3-1). If you use Windows or the K Desktop Environment on a Unix system, you can also drag an icon representing a .ui file from an Explorer/Konqueror window or the desktop onto the Qt Designer window and drop it there.

Figure 3-1. The load icon

You will see your form as you have left it. Qt Designer does not care about any generated source files; all it uses, both when saving and when loading, are the XML-based .ui files. [1]

This behavior of Qt Designer has one important consequence: Never change the files generated by uic! Any changes will be lost once you change the .ui file, save it, and rerun uic. If you need to change some of the generated code—e.g., because you want to add some functionality—you have to do this by subclassing. We'll see in a minute how to do that, but first let's define the objectives of this tutorial:

We will now implement these features one by one.

Notes

[1] Or tmake project files, as you will learn in the section called Using tmake For Generating And Building Qt Designer Files in Chapter 5.