The K Desktop Environment

Next Previous Table of Contents

6. The Dialogeditor: Where your Dialogs are Build

6.1 What the Dialogeditor provides

The built-In dialogeditor of KDevelop is designed to help you construct widgets and dialogs that fit your application's purpose and reduces the time rapidly to extend the GUI of your application. The only limitation for now is that the dialogeditor does not support geometry management that is provided by Qt; therefore the dialogs are static in their size and this may lead to certain circumstances where e.g. the label width is not long enough to support the full length of a translation.

On the other hand, the current state of the editor in conjunction with KDevelop's project management offers the fastest way to create full-featured applications for the K Desktop Environment.

6.2 Qt and KDE Widgets

Currently provided widgets are:

QT-Widgets:

KDE-Widgets:

6.3 Properties of Qt supported Widgets

The following chapter gives a complete overview over the currently supported widgets of the Qt toolkit. To achieve a better understanding of the properties, these are separated to their inheritance. As all of them inherit QWidget, this class is described first. All QWidget properties are available for all other widgets as well, so these are not listed for them again. For widget groups that inherit an abstract subclass of QWidget as their base-class, the base-classes' properties are listed first (though this class does not provide a widget in the dialogeditor itself). Then the widget properties for the available widget of the group contains the properties that are specific to it. For a better understanding the inheritance tree of the available widgets is listed below:

QWidget Properties

QWidget is the base class for almost all widgets in Qt and KDE. Therefore widgets that inherit QWidget will allow to use the same settings in most cases.

QButton inherited widgets

QButton is an abstract widget class that provides properties common to buttons.

Inherits QWidget

Inherited by QCheckBox, QPushButton and QRadioButton inherit QButton.

QCheckBox Properties

Inherits QWidget and QButton

QPushButton Properties

Inherits QWidget and QButton

QRadioButton Properties

Inherits QWidget and QButton

QComboBox Properties

Inherits QWidget

( no additional properties for now)

QFrame inherited widgets

Inherits QWidget

For now only used as an abstract class.

QGroupBox Properties

Inherits QWidget and QFrame

QLCDNumber Properties

Inherits QWidget and QFrame

QLabel Properties

Inherits QWidget and QFrame

QProgressBar Properties

Inherits QWidget and QFrame

QScrollView

Inherits QWidget and QFrame

Inherited by QListBox (abstract for now)

Provides a scrollable widget that manages the display of a child widget by a vertical and horizontal scrollbar.

QListView

Inherits QWidget, QFrame and QListView

Provides a list view to display hierarchical data either in a table or a tree. Manages itself by scrollbars through QScrollView.

QSpinBox Properties

Inherits QWidget and QFrame

QTableView inherited widgets

Inherits QWidget, QFrame and QTableView

Inherited by QListBox and QMultiLineEdit

QListBox Properties

Inherits QWidget, QFrame and QTableView

QMultiLineEdit Properties

Inherits QWidget, QFrame and QTableView

QLineEdit Properties

Inherits QWidget

QScrollBar Properties

Inherits QWidget and QRangeControl.

QSlider Properties

Inherits QWidget and QRangeControl.

6.4 Properties of KDE supported Widgets

KColorButton

Inherits QPushButton

KKeyButton

KCombo

Inherits: QComboBox

KDatePicker

KLedLamp

KProgress

KSeparator

KDateTable

KTreeList

KRestrictedLine

KLed

Inherits QWidget

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" from the "File" menu. Select "Qt/KDE Dialgo (*.kdevdlg) from the New File dialog and enter the dialog filename. Construct your dialog and when you´re finished, select "Generate all Sources" from the "Build"-menu.

Then enter all needed information to the appearing 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:

6.6 Setting Widget Properties

Widget properties can be set easily with the properties window entries. When a widget gets selected, the properties window automatically updates to the properties of the current widget. As all widgets are derived from QWidget, you can set the QWidget properties plus an amount of properties that are specific to the selected widget. Properties can be:

6.7 Integrating the Dialog

Whenever you created a widget, you probably want to add it to the project to execute the action it is designed for. As a widget can be constructed for several purposes, we will watch for two cases: a QWidget inherited widget and a QDialog one.

QWidget inherited

Let's say you created a widget that will be part of the main view. If it fills the whole view area, you have to add an instance pointer to the header declaration of your KTMainWindow instance replacing the currently set view widget. Then change the code in the initView method to set this widget the main view. Additionally, you could remove the View class of the generated project, but mind that the document instance and the App instance depends on the view class. In this case, it is technically a much better way to create a mini-KDE application and construct your KTMainWindow instance yourself.

More often the widget is intended to be a part of the view area, which means it is combined with other widgets. This can be done by using one of the following classes that provide a divider to separate two widgets:

  1. QSplitter
  2. KPanner
  3. KNewPanner

If the main view shall contain more than two widgets, you have to use another instance of the divider as one of the two managed widgets by the first one. Then add the according widgets to each panner and set the first panner the view area.

QDialog inherited

If your widget inherits QDialog, it is probably intended to change one or more values; often this is used to set the application preferences. To invoke the dialog, you have to add a slot to the App class by adding the method declaration and the implementation body. Then add the constructor call to the method as well as a call to show() or exec() the dialog. Finally, you should take care for processing the results of the dialog; this can either be done by the dialog who changes values of the parent widget itself or by retrieving the values from the dialog (which would make your dialog a lot more reusable in other projects). Mind that you should call delete if you called the dialog instance with new to avoid memory leaks.

Finally, you have to connect a menuentry (with according statusbar help) to the new slot invoking the dialog; optionally a keyboard accelerator and a toolbar icon. For this, add a resource ID to the file resource.h with a define. Then add an according menuentry to one of the popup menus already present in the menubar or create a new popup to add your menuentry. The menuentry consists of:

Next Previous Table of Contents