Qt 4: The book

Page 104

4 Developing a GUI Application Based on a Main Window

Figure 4.1: Anatomy of a main window

A bare main window, as shown in Figure 4.2, initially consists only of the central widget and frame, plus a title bar.1 In order to conjure this minimal arrangement onto the screen, nothing more than a simple program that instantiates a QMainWindow object and sets a label announcing it as the central widget is required. So that the lettering is displayed with centered alignment by the label, we use the <center> tag: QLabel interprets certain HTML tags as markup, rather than as text: // mainwindow/main.cpp #include <QApplication> #include <QMainWindow> #include <QLabel> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow mainWindow; QLabel *label = new QLabel("<center>Central Widget</center>"); mainWindow.setCentralWidget(label); mainWindow.show(); return a.exec(); }

This example is therefore different from the one introduced in Chapter 1.1 (page 25), in particular because we display a label within a QMainWindow instance. The result is shown in Figure 4.2. 1

102

Under X11, there are a few window managers that do not show any decoration around the window.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.