Results 1 to 2 of 2

Thread: QWinWidget Inside MFC Control Not Repainting or Responding to Tab/Arrow keys

  1. #1

    Default QWinWidget Inside MFC Control Not Repainting or Responding to Tab/Arrow keys

    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.

    Repainting
    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).

    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.

    Keyboard Input
    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.

    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.
    Last edited by average; 30th June 2009 at 22:32.

  2. #2

    Default Re: QWinWidget Inside MFC Control Not Repainting or Responding to Tab/Arrow keys

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

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

    Qt Code:
    1. SetWindowLong(winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP);
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. if(msg->message == WM_GETDLGCODE)
    2. {
    3. *result = DLGC_WANTARROWS | DLGC_WANTTAB;
    4. return(true);
    5. }
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. MFC Control in a Qt Tab Widget
    By average in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2009, 21:40
  3. QWinwidget loses focus
    By salix in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2009, 21:54
  4. Check a point inside or outside a road?
    By kstking in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2007, 18:48
  5. Replies: 6
    Last Post: 3rd February 2006, 09:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.