Qt GUI Widgets

Table of contents:

This chapter provides an overview of the GUI building blocks, called widgets, that are part of the Qt library and includes some simple examples of how to use them.


Widget Categories



QMainWindow and QSettings






Images and Resources



Layout of Widgets



QActions, QMenus, and QMenuBars



QActions, QToolbars, and QActionGroups



Regions and QDockWidgets



Views of a QStringList


Widgets, objects of classes derived from QWidget, are reusable building blocks with a visual representation on the screen. The common features of a QWidget are shown in Figure 11.1.

Figure 11.1. QWidget's Heritage

QWidget is a class that uses multiple inheritance (see Section 23.3). A QWidget is a QObject, and thus can have parents, signals, slots, and managed children. A QWidget is a QPaintDevice, the base class of all objects that can be "painted."

QWidgets interact with their children in interesting ways. A widget that has no parent is called a window. If one widget is a parent of another widget, the boundaries of the child widget lie completely within the boundaries of the parent. The contained child widget is displayed according to layout rules (see Section 11.5).

A QWidget can handle events by responding to signals from various entities in the window system (e.g., mouse, keyboard, other processes, etc.). It can paint its own rectangular image on the screen. It can remove itself from the screen in a way that respects whatever else is on the screen at the moment.

A typical desktop GUI application can contain many (hundreds is not unusual) different QWidget-derived objects, deployed according to parent-child relationships and arranged according to the specifications of the applicable layouts.

A QWidget is considered to be the simplest of all GUI classes, because it is rendered as an empty box. The class itself is quite complex, containing hundreds of functions. When you reuse QWidget and its subclasses you are standing on the shoulders of giants, because every QWidget is built on top of layers of Qt code, which in turn are built on top of different layers of native widget libraries, depending on your platform (X11 in Linux, Cocoa on MacOS, and Win32 in Windows).

In fact, QWidget is a Façade for the widget classes from each of these native window libraries (see Section 16.3).

Widget Categories

Part I: Introduction to C++ and Qt 4

C++ Introduction


Introduction to Qt



Inheritance and Polymorphism

Part II: Higher-Level Programming


Introduction to Design Patterns


Generics and Containers

Qt GUI Widgets


Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments


MP3 Jukebox Assignments

An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net