Chapter 5. A Guided Tour Through the Qt Dialog Boxes

Dialog boxes are important in every GUI-based application. Even simple applications usually have several dialog boxes, and in applications of medium complexity, it is not uncommon to have 50 or more dialog boxes. Therefore, a GUI developer builds dialog boxes often. In this chapter, we look at the facilities Qt provides for building dialog boxes. We start with predefined dialog boxes that cover a well-defined task, which can usually be used out of the box. Afterwards, we look at building blocks you can use to create your own dialog boxes.

Predefined Dialog Boxes

Predefined dialog boxes are nice for the stressed developer because you can get good results with very little coding. Often only one line of code will suffice to customize these boxes for your purposes.

Qt currently provides several predefined dialog boxes that are used frequently: QColorDialog for selecting a color, QFileDialog for specifying files and directories, QFontDialog for selecting a font, QInputDialog for entering a one-line textual value, QProgressDialog for showing progress in lengthy operations, QMessageBox for general messages, and QErrorMessage for error messages that the user can select not to show again. We will look at each of these boxes in turn.

File Selection Dialog Boxes

QFileDialog (see Figure 5-1) provides a File Selection dialog box. It lets the user choose a file for opening, saving, or other file-related operations. Most of the time, QFileDialog ...

Get Programming with Qt, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.