Chapter 10.  MainWindows and Actions

Table of Contents

10.1. QActions, QMenus, and QMenuBars
10.1.1. QActions, QToolbars, and QActionGroups
10.1.2. Exercise: CardGame GUI
10.2. Regions and QDockWidgets
10.3. QSettings: Saving and Restoring Application State
10.4. Clipboard and Data Transfer Operations
10.5. The Command Pattern
10.5.1. QUndoCommand and Image Manipulation
10.5.1.1. Exercises: QUndoCommand and Image Manipulation
10.6. tr() and Internationalization
10.7. Exercises: MainWindows
10.8. Review Questions

[ fromfile: mainwindows.xml id: mainwindows ]

Most QApplications manage a single QMainWindow. As Figure 10.1 shows, the QMainWindow has some features that are common to most desktop applications.

Figure 10.1.  A Main Window

A Main Window

In most applications, the QMainWindow is the (grand)parent object of all QAction, QWidget, and QObject heap objects. It is common practice to extend that class for applications, as shown in Example 10.1.

Example 10.1. src/widgets/mainwindow/mymainwindow.h

[ . . . . ]
class MyMainWindow : public QMainWindow {
    Q_OBJECT
 public:
    explicit MyMainWindow(QWidget* parent=0);
    void closeEvent(QCloseEvent* event); 1

 protected slots:
    virtual void newFile();
    virtual void open();
    virtual bool save();
[ . . . . ]

1

Overridden from base class to capture when the user wants to close the window