![]() |
KDWinUtils
Helper library for MFC to Qt migration
|
The KDWinUtils library provides classes with an API close the the MFC API, but using Qt underneath. As a Qt developer, you have access to the whole Qt API.
The library contains data primitives that are compatible with Qt:
| KDWinUtils class | Qt class | Comment |
|---|---|---|
| KImageList | QList<QImage> | Is a QList<QImage> |
| KPoint | QPoint | |
| KRect | QRect | |
| KSize | QSize | |
| KString | QString | Inherits QString |
| KStringArray | QStringList | Is a QList<Kstring> |
Note that KPoint (respectively KRect or KSize) is not QPoint (respectively QRect or QSize), but can be implicitly converted into it.
The equivalent of QWidget in MFC is a CWnd. The KWidget class inherits from QWidget, with some of the MFC API to minimize code changes.
The KWidget class has its own event handling (called from the Qt event handling messages) The KWidget class has its own methods to handle events, like OnLButtonDown, OnPaint... the name should be explicit enough. They are called from the Qt event handlers.
A Qt developer can always reimplement the Qt event handler methods.
In Windows, events and communication between components are handled using messages. You can read more here: Message Handling and Mapping.
The KWidget has such a system in place. It uses connectMessage to map a message ID to a message handler, meaning every time the class receives a message with this ID, the message handler will be called.
To send a message, it uses SendMessage for synchronous calls, and PostMessage for asynchronous calls. The message goes through the Qt event loop, using the KMessageEvent event.
Some flags can be set on the KWidget class using setFlags. Particularly Flag::HScroll and Flag::VScroll, which creates a scroll area in the widget, with a horizontal and/or a vertical scrollbar.
In this setup, painting using the OnPaint method is done on the scroll area, not the widget itself. In this setup:
will create a painter not on the MyWidget class, but on the viewport of the scroll area.
The KDialog class is the base class for dialogs. Like for widgets, it's based on QDialog, with some API from CDialog.

Even if they don't inherit from each other, KWidget and KDialog share most of the same API, with some additions to KDialog`.
The OnInitDialog method is specific to the way MFC is initializing a dialog: this method is called the first time the dialog is shown:
The library contains some proxy classes that add some MFC API on top of existing widgets.
| KDWinUtils class | Underlying widget |
|---|---|
| KCheck | QAbstractButton |
| KComboBox | QComboBox |
| KEdit | QLineEdit |
| KMultiEdit | QTextEdit |
| KNumber | QLineEdit, QLabel, QSpinBox |
| KSliderCtrl | QSlider |
| KTabCtrl | QTabBar |
| KText | QLineEdit, QLabel, QSpinBox |
There's also a KButtonGroup, which is a QButtonGroup with some int conversion operators.