Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
For Qt developers

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.

Primitives data

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.

Widgets

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.

Event handling

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.

Message handling

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.

Scroll flags

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:

void MyWidget::OnPaint(QPaintEvent *event) {
KPainter painter(this);
}
The KPainter class is used to paint on a widget.
Definition kpainter.h:51

will create a painter not on the MyWidget class, but on the viewport of the scroll area.

Dialogs

The KDialog class is the base class for dialogs. Like for widgets, it's based on QDialog, with some API from CDialog.

KWidget/KDialog class diagram

Even if they don't inherit from each other, KWidget and KDialog share most of the same API, with some additions to KDialog`.

Dialog initialisation

The OnInitDialog method is specific to the way MFC is initializing a dialog: this method is called the first time the dialog is shown:

void KDialog::showEvent(QShowEvent *event)
{
if (!m_initDone) {
m_initDone = true;
}
QDialog::showEvent(event);
}
void showEvent(QShowEvent *event) override
virtual bool OnInitDialog()
Initializes the dialog internal data.
Definition kdialog.h:56
bool event(QEvent *e) override
Definition kwidget.h:654

Proxy classes

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.