Results 1 to 6 of 6

Thread: MFC Control in a Qt Tab Widget

  1. #1

    Default MFC Control in a Qt Tab Widget

    I'm working on a project that is using the Qt/MFC Migration Framework and I'm trying to reuse some existing MFC controls inside of a Qt dialog.

    Does anyone know if it is possible to insert an MFC control (CDialog or CWnd) inside of a QTabWidget. Right now we're doing the opposite, we have an MFC dialog with a tab control which is populated with a mix of MFC tabs (CDialog) and Qt tabs (QWinWidget). However, this approach is giving me a headache because the QWinWidget controls are not properly being drawn nor are they receiving focus or keyboard input correctly. I am hoping that using a Qt dialog with a QTabWidget will work better than this approach.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MFC Control in a Qt Tab Widget

    Quote Originally Posted by average View Post
    Does anyone know if it is possible to insert an MFC control (CDialog or CWnd) inside of a QTabWidget.
    I think you should use QWinHost.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: MFC Control in a Qt Tab Widget

    Can anyone provide me with an example of how to use this QWinHost to wrap an MFC CWnd or CDialog class so that the control can be used in a QTabWidget? I've been banging my head for a while with this, and I can't seem to get anything to work.

    I'm trying to follow the example Qt has that shows how a Win32 control has been wrapped in the QWinHost. They derive a class from QWinHost and override the createWindow function to specify how to create the Win32 control. This is one of my problems because the createWindow class passes in a HWND for the parent, but all MFC classes require a CWnd object as a parent. I've tried every permutation of CWnd::FromHandle, CWnd::FromPermanentHandle, CWnd::Attach, etc, and I can't seem to get anything to work. It seems to me that the QWinHost wasn't designed for wrapping MFC controls.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MFC Control in a Qt Tab Widget

    It was designed specifically for that. Have you tried simply calling setWindow() on the QWinHost instance?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: MFC Control in a Qt Tab Widget

    Is this the correct usage of the QWinHost in the context of MFC?
    Qt Code:
    1. QDialog* lpDialog = new QDialog();
    2.  
    3. CDialog* lpMfcDlg= new CDialog();
    4. lpMfcDlg->Create(IDD_DIALOG);
    5.  
    6. QWinHost* lpChild = new QWinHost(lpDialog);
    7. lpChild->setWindow(lpMfcDlg->GetSafeHwnd());
    8.  
    9. lpDialog->ui.tabWidget->addTab(lpChild);
    To copy to clipboard, switch view to plain text mode 

    Interestingly, when I do this, nothing crashes, but the tab housing the MFC control does not display its contents, and in fact does not draw anything (the previous visited tab's contents are still being drawn indicating that this tab is literally drawing nothing - not even covering up what was drawn before).

    Another thing I've noticed is that the CMyMfcDlg::OnInitDialog method is not being called, but it is called if I were to do this instead: CMyMfcDlg:: DoModal( ).

    EDIT: lpMfcDlg->GetSafeHwnd() was returning NULL, but I corrected that and it is still not working. The tab is still unresponsive/not being drawn.
    Last edited by average; 30th June 2009 at 21:26.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MFC Control in a Qt Tab Widget

    It all might be because you are trying to manipulate the shown/hidden state of the mfc control (when placing it in a host). I never used QWinHost so I'm merely guessing here, but what happens if you use QWinHost for a non-MFC widget or when you don't place the mfc control in a tab widget?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 19th February 2012, 11:40
  2. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  3. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 22:29
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  5. Replies: 6
    Last Post: 3rd February 2006, 09:48

Tags for this Thread

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.