M
M
maaGames2019-08-14 12:39:07
Qt
maaGames, 2019-08-14 12:39:07

Is it possible to embed QT dialog in MFC CDialog?

Is it possible to embed QT dialog in MFC CDialog?
It doesn't matter if it's inheritance, encapsulation, or something else.
I know it's a perversion, but there is no choice.
The application supports modeless windows in which you can insert your own dialogs inherited from CDialog. I would like to write a plugin in QT and use it not only with this application, but also with others and as stand-alone. Now this is only possible if you write using MFC, but I want to switch to more convenient GUI programming and stop suffering ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maaGames, 2020-01-08
@maaGames

In general, for a dialog (or any widget) we get a screw HWND, after which we push it into the existing dialog using the 'HWND oldparent =SetParent( HWND child, HWND parent)' method. After that, the widget becomes a child window of standard Windows dialogs, including MFC ones (from the user's point of view, it behaves like a normal dialog control, i.e. there is no visual difference, which was what was required). Before deleting the dialog, you need to return the parent for the widget.

#include <QtGui/5.12.6/QtGui/qpa/qplatformnativeinterface.h>

QWindow * windowForWidget( const QWidget * widget )
{
  QWindow * window = widget->windowHandle();
  if( window )
    return window;

  const QWidget * nativeParent = widget->nativeParentWidget();
  if( nativeParent )
    return nativeParent->windowHandle();

  return nullptr;
}

HWND getHWNDForWidget( const QWidget * widget )
{
  QWindow * window = ::windowForWidget( widget );
  if( window && window->handle() )
  {
    QPlatformNativeInterface * iface = QGuiApplication::platformNativeInterface();
    return static_cast<HWND>(iface->nativeResourceForWindow( QByteArrayLiteral( "handle" ), window ));
  }

  return nullptr;
}

5e1585cb462c4267495335.png

T
tsarevfs, 2019-08-14
@tsarevfs

It will most likely be quite difficult.
https://stackoverflow.com/questions/25025168/event...
https://github.com/qtproject/qt-solutions/tree/mas...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question