Constructing a new Dialog

O Manual de Programação do KDevelop: O Guia do Utilizador para Desenvolvimento de Aplicações C++ para o Ambiente de Trabalho K (KDE) com o ambiente de trabalho KDevelop, Versão 2.1
Prev | Capítulo 6. The Dialogeditor: Where your Dialogs are Build | Next

# 6.5. Constructing a new Dialog

Constructing a new dialog is very easy if you already have experience with graphical construction applications. KDevelop offers to create a widget visually and displays the look as it will be shown to the user directly. Further, you can have a preview of your widget by selecting "Preview" from the "View" menu.

To begin constructing a dialog or any other widget, switch to the Dialogeditor and select "New Dialog" from the "File" menu. Then enter all needed information to the "New Dialog" dialog. Those are:

1. The Dialog inheritance. This is necessary because any widget is at least derived from `QWidget`. Besides the widget types provided by Qt , you can inherit e.g. form an abstract base class you constructed yourself within your project. In this case, select "custom" and enter the header file path to the line edit below.

2. The Dialog name. This sets the class name of the generated dialog. Select a classname that is descriptive for what the dialog does; in cases of inheritance from `QDialog`, you may enter a name that ends with `Dlg` to remember yourself it's a dialog. Naming convention should match that of KDE and Qt : Use uppercase letters for your classname. For e.g. a grid-size selection dialog, you would enter `GridSizeDlg`.

3. The generated filenames. Those are preset when entering the dialog name, but can be changed afterwards. If you want to use other filenames, the naming convention should also match that of KDE and Qt : the filenames are all lowercase and contain the classname to remember what class is kept where. The data file that has to be set will later contain the generated code that will build up your dialog. You should not edit this file manually afterwards; use the implementation file for any additions towards dialog construction code and method implementations.

The dialog will then show itself as a widget with a grid. As the dialogeditor uses the grid to snap any child widgets to the geometry, you can change the grid size with the "Grid Size" entry in the "View" menu, if the preset values don't match your needs.

Then select the "Widgets" tabulator on the left pane and press the button for the widget item you want to add to the main widget. It directly appears on the main widget's left upper corner and gets selected by a resizable frame. Then move or resize the widget with the mouse. The cursor will change to indicate which action can be done at the current position.

After having finished the construction, select "Generate Files" from the "Build" menu or hit the according toolbar button. The files will then be generated at the preset location and included into your project sources. A rebuild or make will compile all generated files within your project and you can add the according constructor call to the application to invoke the dialog or widget. For KDE projects, all widget properties that will be visible later, e.g. label texts, are set with the `i18n()` macro of `kapp.h` to support internationalization. Therefore you should do a "Make Messages and merge" when finished with construction and implementation.

When creating a dialog or widget, you should watch the following guidelines:

- Always try to be consistent! This is probably the most important rule when constructing GUI elements. Mind that the user will only accept an application that is easy to understand no matter how complex it's purpose may be.

- Add help wherever you can by tool-tips, What's this..? help or Quick-help. This allows getting direct information about the purpose of the GUI elements.

- watch the keyboard focus ! The generator does not take care of that- this has to be watched when constructing any widget; otherwise you have to reorder your initialization code by hand which is a very unthankful job. The keyboard focus on any widget means the oder on which items get the keyboard input focus when the user presses the tab and shift+tab button. It would be very annoying if the focus changes everywhere but not to the next widget visible below or to the right of the current widget. Therefore start constructing your widget top down from left to right to ensure the consistency of the focus.

Prev | Home | Next
Properties of KDE supported Widgets | Up | Setting Widget Properties