Built-in Widget and Dialog Classes

Qt provides a complete set of built-in widgets and common dialogs that cater for most situations. In this section, we present screenshots of almost all of them. A few specialized widgets are deferred until later: Main window widgets such as QMenuBar, QPopupMenu, and QToolBar are covered in Chapter 3, and database widgets such as QDataView and QDataTable are covered in Chapter 12. Most of the built-in widgets and dialogs are used in the examples presented in this book. In the screenshots below, the widgets are shown using the classic Windows style.

Figure 2.17. Qt's button widgets


Qt provides three kinds of "buttons": QPushButton, QCheckBox, and QRadioButton. QPushButton is most commonly used to initiate an action when it is clicked, but it can also behave like a toggle button (click to press down, click to release). QRadioButtons are usually used inside a QButtonGroup and are mutually exclusive within their group, whereas QCheckBox can be used for independent on/off options.

Figure 2.18. Qt's container widgets


Qt's container widgets are widgets that contain other widgets. QFrame can also be used on its own to simply to draw lines and is inherited by many other widget classes, notably QLabel and QLineEdit. QButtonGroup is not shown; it is visually identical to QGroupBox.

QTabWidget and QToolBox are multi-page widgets. Each page is a child widget, and the pages are numbered from 0.

Figure 2.19. Qt's item view widgets


The item views are optimized for handling large amounts of data, and often use scroll bars. The scroll bar mechanism is implemented in QScrollView, a base class for item views and other kinds of views.

Figure 2.20. Qt's display widgets


Qt provides a few widgets that are used purely for displaying information. QLabel is the most important of these, and it can be used for showing rich text (using a simple HTML-like syntax) and images.

QTextBrowser (not shown) is a read-only QTextEdit subclass that has basic HTML support including lists, tables, images, and hypertext links; Qt Assistant uses QTextBrowser to present documentation to the user.

Figure 2.21. Qt's input widgets


Qt provides many widgets for data entry. QLineEdit can restrict its input using an input mask or a validator. QTextEdit is a QScrollView subclass capable of editing large amounts of text.

Figure 2.22. Qt's color dialog and font dialog


Qt provides the standard set of common dialogs that make it easy to ask the user to select a color, font, or file, or to print a document.

Figure 2.23. Qt's file dialog and print dialog


On Windows and Mac OS X, Qt uses the native dialogs rather than its own common dialogs when possible.

Figure 2.24. Qt's feedback dialogs


Qt provides a versatile message box and an error dialog that remembers which messages it has shown. The progress of time-consuming operations can be indicated using QProgressDialog or using the QProgressBar shown earlier. QInputDialog is very convenient when a single line of text or a single number is required from the user.

Finally, QWizard provides a framework for creating wizards. Qt Designer provides a "Wizard" template for creating wizards visually.

Figure 2.25. Qt's QWizard dialog


A lot of ready-to-use functionality is provided by the built-in widgets and common dialogs. More specialized requirements can often be satisfied by connecting signals to slots and implementing custom behavior in the slots.

In some situations, it may be desirable to create a custom widget from scratch. Qt makes this straightforward, and custom widgets can access all the same platform-independent drawing functionality as Qt's built-in widgets. Custom widgets can even be integrated with Qt Designer so that they can be used in the same way as Qt's built-in widgets. Chapter 5 explains how to create custom widgets.

Part I: Basic Qt

Getting Started

Creating Dialogs

Creating Main Windows

Implementing Application Functionality

Creating Custom Widgets

Part II: Intermediate Qt

Layout Management

Event Processing

2D and 3D Graphics

Drag and Drop


Container Classes





Providing Online Help


Platform-Specific Features

show all menu

C++ GUI Programming with Qt 3
C++ GUI Programming with Qt 3
ISBN: 0131240722
EAN: 2147483647
Year: 2006
Pages: 140
Similar book on Amazon

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