Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
QWinHost Class Reference

The QWinHost class provides an API to use native Win32 windows in Qt applications. More...

#include <qwinhost.h>

Inheritance diagram for QWinHost:
[legend]
Collaboration diagram for QWinHost:
[legend]

Public Member Functions

 QWinHost (QWidget *parent=0, Qt::WindowFlags f={})
 
void setWindow (HWND)
 
HWND window () const
 
 ~QWinHost ()
 

Protected Member Functions

virtual HWND createWindow (HWND parent, HINSTANCE instance)
 
bool event (QEvent *e)
 
void focusInEvent (QFocusEvent *)
 
bool nativeEvent (const QByteArray &eventType, void *message, qintptr *result)
 
void resizeEvent (QResizeEvent *)
 
void showEvent (QShowEvent *)
 

Friends

void * getWindowProc (QWinHost *host)
 

Detailed Description

The QWinHost class provides an API to use native Win32 windows in Qt applications.

QWinHost exists to provide a QWidget that can act as a parent for any native Win32 control. Since QWinHost is a proper QWidget, it can be used as a toplevel widget (e.g. 0 parent) or as a child of any other QWidget.

QWinHost integrates the native control into the Qt user interface, e.g. handles focus switches and laying out.

Applications moving to Qt may have custom Win32 controls that will take time to rewrite with Qt. Such applications can use these custom controls as children of QWinHost widgets. This allows the application's user interface to be replaced gradually.

When the QWinHost is destroyed, and the Win32 window hasn't been set with setWindow(), the window will also be destroyed.

Constructor & Destructor Documentation

◆ QWinHost()

QWinHost::QWinHost ( QWidget * parent = 0,
Qt::WindowFlags f = {} )

Creates an instance of QWinHost. parent and f are passed on to the QWidget constructor. The widget has by default no background.

Warning
You cannot change the parent widget of the QWinHost instance after the native window has been created, i.e. do not call QWidget::setParent or move the QWinHost into a different layout.

◆ ~QWinHost()

QWinHost::~QWinHost ( )

Destroys the QWinHost object. If the hosted Win32 window has not been set explicitly using setWindow() the window will be destroyed.

Member Function Documentation

◆ createWindow()

HWND QWinHost::createWindow ( HWND parent,
HINSTANCE instance )
protectedvirtual

Reimplement this virtual function to create and return the native Win32 window. parent is the handle to this widget, and instance is the handle to the application instance. The returned HWND must be a child of the parent HWND.

The default implementation returns null. The window returned by a reimplementation of this function is owned by this QWinHost instance and will be destroyed in the destructor.

This function is called by the implementation of polish() if no window has been set explicitly using setWindow(). Call polish() to force this function to be called.

See also
setWindow()

◆ event()

bool QWinHost::event ( QEvent * e)
protected

\reimp

◆ focusInEvent()

void QWinHost::focusInEvent ( QFocusEvent * e)
protected

\reimp

◆ nativeEvent()

bool QWinHost::nativeEvent ( const QByteArray & eventType,
void * message,
qintptr * result )
protected

\reimp

◆ resizeEvent()

void QWinHost::resizeEvent ( QResizeEvent * e)
protected

\reimp

◆ setWindow()

void QWinHost::setWindow ( HWND window)

Sets the native Win32 window to window. If window is not a child window of this widget, then it is reparented to become one. If window is not a child window (i.e. WS_OVERLAPPED is set), then this function does nothing.

The lifetime of the window handle will be managed by Windows, QWinHost does not call DestroyWindow. To verify that the handle is destroyed when expected, handle WM_DESTROY in the window procedure.

See also
window(), createWindow()

◆ showEvent()

void QWinHost::showEvent ( QShowEvent * e)
protected

\reimp

◆ window()

HWND QWinHost::window ( ) const

Returns the handle to the native Win32 window, or null if no window has been set or created yet.

See also
setWindow(), createWindow()

Friends And Related Symbol Documentation

◆ getWindowProc

void * getWindowProc ( QWinHost * host)
friend

The documentation for this class was generated from the following files: