Gantt Charts in Qt Applications
KD Gantt is a package for creating Gantt charts in Qt applications. It features a large number of configuration options to tailor the charts to your needs. Since all configuration settings have reasonable defaults, you can usually get by with setting only a handful of parameters and relying on the defaults for the rest.
Definition of a Gantt Chart
A Gantt chart is a horizontal bar chart used to schedule and track different tasks in, for example, a software project or a calendar. It is constructed with a horizontal axis showing a time line that can be divided into several smaller parts, such as hours, days, weeks, etc. A Gantt chart also has a vertical axis containing the various tasks included in the project. These tasks can be stand-alone tasks or sub-items to other tasks. The main widget is separated into two views, the left one containing the tasks, and the right one containing the actual schedule with the time line.
A Gantt chart is often better the more verbose it is. Below is an extended KD Gantt Chart, with subtasks as well as task links.
Extended KD Gantt chart (the first task was changed to a KDGanttViewSummaryItem)
The task links used in the Gantt chart above show dependencies between the tasks. The reason for having a special color on three of the items is to display that functionality. This feature can come in handy when you might want to direct the viewer's focus to a certain item.
Creating a KD Gantt Chart
The creation of a Gantt chart is an easy and straightforward procedure:
- Create an object of type KDGanttView. This is the actual Gantt view where you will add different items later. When you want to modify the look of your Gantt chart and its items, you should modify this object instead of modifying each item individually. This will result in a more uniform look of the Gantt view.
- Create different objects of KDGanttViewItem. There are three different kinds to choose between: KDGanttViewTaskItem, KDGanttViewSummaryItem and KDGanttViewEventItem.
You will find a detailed description about how to proceed in the Programmer's Manual, as well as ample sample code.
Items
There are three different items available in KD Gantt: Task, Event and Summary items, represented by the three classes KDGanttViewTaskItem, KDGanttViewEventItem and KDGanttViewSummaryItem. Tasks are used both as a regularly scheduled item as well as a Calendar object. Events are for scheduling events. Summary items can summarize several tasks into one and calculate the total time of those tasks from the children's start/end times.
KD Gantt items
The ability to specify the text that will appear in the list view, as well as the internal name of the item, is available in all constructors.
Customizing Items
KD Gantt items are highly configurable:
Customize - Shapes
- Colors: Different types of items have different default colors. The initial default color is set to blue for event items, green for tasks and cyan for summaries.
- Highlight colors: When an item is clicked, it is highlighted. The default color of the item is displayed.
- Start and end time: When a new item is created, its start and end time are set automatically to the current time.
Customize — Start and end time
- Priorities: Every item in the Gantt chart has a priority between 1 and 199. On creation, every item has a default priority of 150.
- Display modes: There are two different display modes – the "normal" mode and the "calendar" mode. When the Gantt view is in calendar mode instead of the "normal" mode, you do not see regular tasks, but rather all tasks belonging to a certain calendar object on one line.
Customize — Calendar mode
- Text and icons: There are several locations in the Gantt chart where you can display text for an item. These locations include the list view, in the actual chart, as tool-tip text and as "What's This" text. You can add an icon to a task in KD Gantt. That icon is then displayed next to the text in the list view.
Customize — Text
- Empty tasks: If you want to, you can have all your empty tasks in the Gantt view displayed as a vertical line.
A detailed description and example code for these features are available in the Programmer's Manual.
Task Links
A task link is an object of type KDGanttViewTaskLink that contains references to tasks that are linked together. A KDGanttViewTaskLink can link several tasks to several other tasks, several tasks to one task or one task to several other tasks.
Grouping Task Links
To modify several task links uniformly at once, you can use KDGanttViewTaskLinkGroup and add several KDGanttViewTaskLink objects to it. Here we show two of the three different ways of assigning a task link to a task link group. The third way is to use KDGanttViewTaskLink::setGroup() and pass it to the group the task link should belong to.
A highlighted task link group
Customizing Task Links
Task link colors
- Text: There are a few places in the KD Gantt view where the text of a task link is displayed, including the tool-tip text and the "What's This?" text.
- Visibility: If you want to change the visibility of a task link or task link group, call either KDGanttViewTaskLink::setVisible() or KDGanttViewTaskLinkGroup::setVisible(), and pass either true or false, depending on what kind of behavior you want.
A detailed description and example code for these features are available in the Programmer's Manual.
Legends
Adding an item to a legend is a very simple process. You just use KDGanttView::addLegendItem() and pass it the shape to add, its color and the legend text to be displayed next to the shape. It is possible to add your own widgets to the legend header.
Legends
There are several different visibility options for the legend and its associated objects:
Legend dock window
Time Line
The time line is highly configurable — it consists of two scales, one major (upper) and one minor (lower). When you change the scale of the time line, you change the scale of the minor scale. The major scale is recalculated automatically from the value of the minor scale.
Different customizable time line scales
Menus and Dialogs
A few dialogs and menus are built into KD Gantt. These include a context menu for the time line, a context menu for the Gantt chart itself and a dialog for viewing/editing the properties of an item, accessible by double-clicking the item. Enabling the menus and the dialog is as simple as calling one method or connecting one slot.
Item properties dialog
Drawing and Updating
Brush example
Customizing
You may customize the following items:
Example of a customized background
- Grid: To improve the readability of the chart, a grid is displayed in the Gantt view. You can modify the appearance of the grid.
- Brushes: You can use brushes in the Gantt view to make it more appealing to the eye.
- Drag-and-Drop: You can enable or disable drag-and-drop in KD Gantt.
Customized Gantt view
Documentation
KD Gantt is delivered with a Programmer's Manual which will get you started with creating your charts. It provides many pointers to advanced features. Besides this manual, there are two other documents:
- Depending on your KD Gantt version, you will find different INSTALL files in the doc directory that explain how to install KD Gantt on your platform or how to build it from the source.
- KD Gantt comes with an extensive Reference Manual that is generated directly from the source code itself. You should refer to these in conjunction with this Programmer's Manual.