Open casper opened 2 years ago
https://stackoverflow.com/q/14610426/8740349
Qt5 replaced winEvent
with nativeEvent
.
Imagine you need to be Qt 4 compatible, and your Window has some transparent parts, which you need to be click-through:
Header:
#ifndef MY_CLASS_H
#define MY_CLASS_H
#include <QtCore/QByteArray>
#include <QWidget>
class MyClass : public QWidget {
typedef QWidget super;
public:
// ...
protected:
#if defined(_WIN32)
# if QT_VERSION_MAJOR >= 5
bool nativeEvent(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
# else
bool winEvent(MSG *message, long *result) Q_DECL_OVERRIDE;
# endif
#endif
private:
Q_DISABLE_COPY(MyClass)
};
#endif // MY_CLASS_H
Source:
#include "my-class.h"
#include <QPoint>
#ifdef _WIN32
# include <Windows.h>
# include <windowsx.h>
#endif
#if defined(_WIN32)
# if QT_VERSION_MAJOR >= 5
bool MyClass::nativeEvent(const QByteArray &eventType, void *messageVoid, long *result)
{
if (eventType == "windows_generic_MSG")
{
MSG *message = reinterpret_cast<MSG *>(messageVoid);
# else
bool MyClass::winEvent(MSG *message, long *result)
{
{
# endif // QT_VERSION_MAJOR
if (message->message == WM_NCHITTEST) {
QPoint pos = this->mapFromGlobal(QPoint(GET_X_LPARAM(message->lParam), GET_Y_LPARAM(message->lParam)));
if ( ! contentsRect().contains(pos)) {
*result = HTTRANSPARENT;
return true; // Stops further processing.
}
}
}
# if QT_VERSION_MAJOR >= 5
return super::nativeEvent(eventType, messageVoid, result);
# else
return super::winEvent(message, result);
# endif // QT_VERSION_MAJOR
}
#endif // _WIN32
Note that Qt5 defines Q_OS_WIN
and Qt4 defines Q_WS_WIN
hence above uses _WIN32
.
Does anyone know if
QWidget::winEvent()
orQApplication::winEventFilter()
is somehow available on qtbindings?I would like to do my own event processing in order to capture
WM_COPYDATA
for some simpe Windows IPC. I found some sample code for Qt C++ here:https://stackoverflow.com/questions/1755196/receive-wm-copydata-messages-in-a-qt-app
I tried searching for
winEvent
andwinEventFilter
in the qtbindings source, but could not find anything. Are these methods missing or how to access them through Ruby?