本文介绍了QWinWidget Inside MFC对话框不重新绘制或响应标签/箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC对话框中使用,并且QWinWidget无法正确绘制本身,并且无法正确处理键盘输入。

I am using a QWinWidget inside of an MFC dialog and the QWinWidget is not drawing itself correctly and it is not handling keyboard input correctly.

QWinWidget,我有一个QTableWidget。当我滚动QTableWidget,它不会重画本身,直到我停止滚动,在这一点,它重绘一切。类似地,我可以在QTableWidget中输入单元格,控件不更新,直到我强制它通过向上或向下滚动重新更新(滚动停止时重新更新)。

Within the QWinWidget, I have a QTableWidget. When I scroll the QTableWidget, it does not redraw itself until I stop scrolling, at which point it redraws everything. Similarly, I can type into cells in the QTableWidget and the control is not updated until I force it to re-update by scrolling up or down (it re-updates when the scrolling stops).

由于这个QWinWidget放在一个MFC CDialog中,我试图覆盖CDialog的OnPaint方法,只调用QWinWidget :: repaint方法,但是这有相反的问题,现在只有QWinWidget被更新,CDialog从来没有重绘,导致工件。如果我调用QWinWidget :: repaint和CDialog :: OnPaint,结果是相同的,没有重写OnPaint方法。有人看过这个问题或知道如何解决这个问题吗?

Since this QWinWidget is housed in an MFC CDialog, I tried overriding the CDialog's OnPaint method and only call the QWinWidget::repaint method, however this has the opposite problem where now only the QWinWidget is updated and the CDialog is never redrawn, resulting in artifacts. If I call QWinWidget::repaint and CDialog::OnPaint, the result is the same as not overriding the OnPaint method. Has anyone ever seen this problem or know how to resolve it?

QWinWidget中的控件会正确响应Tab键或箭头键。标签/箭头键简单地跳过整个QWinWidget(和所有子控件)。即使我点击QWinWidget里面并选择一个控件,下一次按Tab键,它会完全跳过整个QWinWidget的焦点。

None of the controls within the QWinWidget respond to the tab key or arrow keys correctly. The tab/arrow keys simply skip over the entire QWinWidget (and all child controls). Even if I click inside the QWinWidget and select a control, the next time I press the tab key, it skips the focus completely out of the entire QWinWidget.

我注意到QWinWidget有两个函数,QWinWidget :: focusNextPrevChild和QWinWidget :: focusInEvent,他们都有一个注释标题说\reimp。我应该重写这些功能,以获得正确的选项卡功能?

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

推荐答案

我修正了键盘输入问题。 QWinWidget类需要一些变化:

I have fixed the keyboard input issue. The QWinWidget class needed some changes:

在QWinWidget :: init方法中,WS_TABSTOP必须添加到窗口样式:

in the QWinWidget::init method, the WS_TABSTOP must be added to the window style:

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

此外,QWinWidget :: winEvent方法需要响应WM_GETDLGCODE,让Windows知道有兴趣接收键/标签输入。我必须添加这个if块:

Also, the QWinWidget::winEvent method needs to respond to the WM_GETDLGCODE to let Windows know that it is interested in receiving key/tab inputs. I had to add this if block:

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



我还在努力让小部件正确地绘制。

I am still working on getting the widget to paint properly.

这篇关于QWinWidget Inside MFC对话框不重新绘制或响应标签/箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 02:06