[Qt-interest] native HWND in QWidget::create opens separate window
Christopher Lux
christopherlux at gmail.com
Wed Sep 8 14:27:40 CEST 2010
Hi,
i need to use a native window for some special rendering task (on
Windows and Linux). Now on Windows, after i create the Window i call
QWidget::create() using the just created HWND. It seems to work very
well, i can receive events from this window in Qt and so on. But
instead of being embedded instead of the original widget i now have a
second window open.
I want the created window to replace the widget and not open up as a
new window. Is there anything i can do to achieve this?
Here the code snippet to open the window:
wnd_style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
wnd_style_ex = 0;
math::vec2i wnd_position = in_display->_impl->_info->_screen_origin +
in_position;
RECT wnd_rect;
::SetRect(&wnd_rect, 0, 0, in_size.x, in_size.y);
if (0 == ::AdjustWindowRectEx(&wnd_rect, wnd_style, false, wnd_style_ex)) {
...
}
_window_handle = ::CreateWindowEx(wnd_style_ex,
reinterpret_cast<LPCSTR>(in_display->_impl->_window_class),
in_title.c_str(),
wnd_style,
wnd_position.x, wnd_position.y,
wnd_rect.right - wnd_rect.left,
wnd_rect.bottom - wnd_rect.top,
0, 0, in_display->_impl->_hinstance,
0);
Now here is the initialization code of the custom Widget:
viewer_widget::viewer_widget(QWidget* parent, // parent is not 0!
const wm::context::attribute_desc& ctx_attrib,
const wm::surface::format_desc& win_fmt)
: QWidget(parent, Qt::MSWindowsOwnDC)
{
setMouseTracking(true);
setFocusPolicy(Qt::StrongFocus);
setAttribute(Qt::WA_NativeWindow, true);
setAttribute(Qt::WA_PaintOnScreen, true); // disables qt double
buffering (seems X11 only since qt4.5, ...)
//setAttribute(Qt::WA_OpaquePaintEvent, true);
setAttribute(Qt::WA_NoSystemBackground, true);
//setAttribute(Qt::WA_ForceUpdatesDisabled, true);
//setAttribute(Qt::WA_PaintUnclipped, true);
setAutoFillBackground(false);
... after creating the window....
this->create(_window_handle, true, true);
}
Now the window works as expected but comes up as a separate window
instead of replacing the widgets window.
Regards
-chris
More information about the Qt-interest-old
mailing list