[Qt-interest] missing double click event when using native win32 window
Christopher Lux
christopherlux at gmail.com
Mon Sep 13 11:10:37 CEST 2010
Hi,
you can find attached a simple reproduction case for my problem.
I create a custom widget using a native win32 window (simplified for
the demonstration). The custom widget gets all mouse events except the
double click event. You can disable the native widget using the macro
on top of the demo file, then the double click event is fired as
expected.
I was testing this using Qt 4.7.0b2 and rc1 with Visual Studio 2010
and 2008 x64 with the same results. When implementing this under X11
the mouse events fire also as expected, so this might be a Windows
problem.
I hope this example helps to solve the problem.
Regards
-chris
/////////////////////////////////////////////////////////
// code
#define QT_TEST_NATIVE_WND 1
//#undef QT_TEST_NATIVE_WND
#include <iostream>
#include <string>
#include <QtGui/QApplication>
#include <QtGui/QDialog>
#include <Windows.h>
class my_native_window
{
public:
my_native_window(HWND p)
{
HINSTANCE inst = ::GetModuleHandle(0);
std::string class_name("native_wnd_test");
WNDCLASSEX wnd_class;
::ZeroMemory(&wnd_class, sizeof(WNDCLASSEX));
wnd_class.cbSize = sizeof(WNDCLASSEX);
wnd_class.lpfnWndProc = &DefWindowProc;
wnd_class.style = CS_OWNDC;
wnd_class.hInstance = inst;
wnd_class.hbrBackground = 0;//(HBRUSH)::GetStockObject(DKGRAY_BRUSH);
wnd_class.lpszClassName = class_name.c_str();
_window_class = ::RegisterClassEx(&wnd_class);
DWORD wnd_style = 0;
DWORD wnd_style_ex = 0;
HWND parent_wnd = ::GetDesktopWindow();
if (0 != p) {
parent_wnd = p;
wnd_style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD;
}
else {
wnd_style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
}
wnd_style_ex = 0;
_hwnd = ::CreateWindowEx(wnd_style_ex,
reinterpret_cast<LPCSTR>(_window_class),
class_name.c_str(),
wnd_style,
0, 0,
50, 50,
parent_wnd, 0,
inst, 0);
_hdc = ::GetDC(_hwnd);
}
virtual ~my_native_window()
{
if (_hdc) {
::ReleaseDC(_hwnd, _hdc);
}
if (_hwnd) {
::DestroyWindow(_hwnd);
}
}
public:
HWND _hwnd;
HDC _hdc;
ATOM _window_class;
}; // class my_native_window
class my_widget : public QWidget
{
my_native_window* _native_wnd;
public:
my_widget(QWidget* p)
: QWidget(p, Qt::MSWindowsOwnDC),
_native_wnd(0)
{
setMouseTracking(true);
setFocusPolicy(Qt::StrongFocus);
setAttribute(Qt::WA_NativeWindow, true);
//setAttribute(Qt::WA_DontCreateNativeAncestors, false);
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);
#if QT_TEST_NATIVE_WND
_native_wnd = new my_native_window(p->winId());
// ok set the native window as this widgets window...and hold thumbs
this->create(_native_wnd->_hwnd, true, true);
#endif
}
virtual ~my_widget()
{
if (_native_wnd) {
delete _native_wnd;
}
}
void mouseDoubleClickEvent(QMouseEvent* mouse_event)
{
std::cout << "my_widget::mouseDoubleClickEvent() fired" << std::endl;
}
void mousePressEvent(QMouseEvent* mouse_event)
{
std::cout << "my_widget::mousePressEvent() fired" << std::endl;
}
void mouseMoveEvent(QMouseEvent* mouse_event)
{
std::cout << "my_widget::mouseMoveEvent() fired" << std::endl;
}
void mouseReleaseEvent(QMouseEvent* mouse_event)
{
std::cout << "my_widget::mouseReleaseEvent() fired" << std::endl;
}
}; // my_widget
class qt_test : public QDialog
{
my_widget* _widget;
public:
qt_test(unsigned w, unsigned h)
: QDialog(0, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)
{
// because we have no parent
setAttribute(Qt::WA_DeleteOnClose);
_widget = new my_widget(this);
_widget->setFixedSize(w, h);
}
}; // class qt_test
int main(int argc, char **argv)
{
///////////////////////////////////////////////////////////////////////////////////////////////
QApplication app(argc, argv);
qt_test* qt_test_instance(new qt_test(200, 100));
qt_test_instance->setWindowTitle("qt native widget test");
qt_test_instance->show();
return app.exec();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: application/octet-stream
Size: 4706 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100913/ea43064f/attachment.obj
More information about the Qt-interest-old
mailing list