PDA

View Full Version : Problem with keyboard input when using QWinWidget to host Qt widget on CDialog (MFC)



Thart
5th December 2011, 14:58
Hello,

I'm gradually migrating application from MFC to Qt and using MFCMigrationFramework for this purpose.

The main problem is in fact that Qt widget which is placed on MFC dialog doesn't handle such keys as Tab, Arrows, Enter, Esc.
Problem with Tab and arrows was partially solved with this solution (http://stackoverflow.com/questions/1066183/qwinwidget-inside-mfc-dialog-not-repainting-or-responding-to-tab-arrow-keys):

I've subclassed QWinWidget and have made next things:
Constructor:

SetWindowLong(winId(), GWL_STYLE, GetWindowLong(winId(), GWL_STYLE) | WS_TABSTOP);
Overriden winEvent:

bool winEvent(MSG *msg, long *result)
{
switch(msg->message)
{
case WM_GETDLGCODE:
*result = DLGC_WANTARROWS | DLGC_WANTTAB;
return true;
}

return __super::winEvent(msg, result);
}


It works except one issue: it's impossible to reach controls on parent dialog (MFC) using Tab key, focus cycles only through child Qt control (the first issue).

The second issue: Enter and Esc keys are handled only by parent MFC dialog. For instance, it's impossible to close opened popup of combobox (located on Qt widget) by pressing Enter or Esc key - dialog is closed instead (CDialog::OnOK or CDialog::OnCancel is called).

I've tried this

case WM_GETDLGCODE:
*result = DLGC_WANTARROWS | DLGC_WANTTAB | DLGC_WANTALLKEYS;

but in this case CDialog doesn't handle Esc and Enter keys anymore.

What is the right solution to handle such situation?