QWinWidget Inside the MFC dialog does not repaint or does not respond to Tab / Arrow keys

I use QWinWidget inside the MFC dialog, and QWinWidget does not correctly draw and does not handle keyboard input correctly.

Repainting [Unauthorized]

In QWinWidget, I have a QTableWidget. When I look at the QTableWidget, it does not redraw until I stop scrolling, and at that moment it redraws everything. Likewise, I can enter cells in a QTableWidget, and the control does not refresh until I force it to re-refresh by scrolling up or down (it refreshes when the scroll stops).

Since this QWinWidget is located in the CDialog MFC, I tried to override the Onial method for CDialog and only call the QWinWidget :: repaint method, however this has the opposite problem when only QWinWidget is updated and CDialog never redraws, resulting in artifacts. If I call QWinWidget :: repaint and CDialog :: OnPaint, the result is the same as not overriding the OnPaint method. Has anyone seen this problem or knew how to solve it?

Keyboard input [enabled]

None of the controls in QWinWidget will correctly respond to tabs or arrow keys. The tab / arrow keys simply skip the entire QWinWidget (and all child controls). Even if I click inside the QWinWidget and select the control, the next time I press the Tab key, it completely disables focus from the whole QWinWidget.

I noticed that QWinWidget has two functions: QWinWidget :: focusNextPrevChild and QWinWidget :: focusInEvent, and both of them have a comment header with the inscription "\ reimp". Do I have to override these functions in order to get the correct tab functionality? If so, how can these functions be implemented to properly configure the tab.

+3
source share
4

. QWinWidget :

QWinWidget:: init, WS_TABSTOP :

SetWindowLong(winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP);

, QWinWidget:: winEvent WM_GETDLGCODE, Windows , /. if:

if(msg->message == WM_GETDLGCODE)
{
   *result = DLGC_WANTARROWS | DLGC_WANTTAB;
   return(true);
}

, .

+3

, focusNextPrevChild() focusInEvent(), , "\ reimp" Qt, , .

+1

I don’t know about keyboard input, but about repainting: did you try calling QWinWidget :: repaint () in the OnialCialog method after you called CDialog :: OnPaint ()?

0
source

Thanks! It works for me! I fixed the arrow navigation issue for QTableView inside QWinWidget. I am using Qt5.3.0 and qtwinmigrate 2.8. You must change the QWinWidget :: nativeEvent method.

#if QT_VERSION >= 0x050000
bool QWinWidget::nativeEvent(const QByteArray &, void *message, long *result)
#else
...
{
    ...
    if (msg->message == WM_SETFOCUS) {
        ...
    } else if (msg->message == WM_GETDLGCODE) {
        *result = DLGC_WANTALLKEYS;
        return true;
    }

    return false;
}
0
source

Source: https://habr.com/ru/post/1711622/


All Articles