Thanks, subclassing QAbstractNativeEventFilter and installNativeEventFilter worked. I doubt that this is what you meant, but this is what I did.
Subclassing QAbstractNativeEventFilter:
#include<QAbstractNativeEventFilter>
#include <QObject>
class CCustomEventFilter
: public QObject,
public QAbstractNativeEventFilter
{
Q_OBJECT
public:
CCustomEventFilter
(QObject *parent
= 0);
~CCustomEventFilter();
virtual bool nativeEventFilter
(const QByteArray &eventType,
void *message,
long *result
) Q_DECL_OVERRIDE;
signals:
void ShiftKeyDown();
void ShiftKeyUp();
};
.cpp file
#include "ccustomeventfilter.h"
#include "windows.h"
standard default constructor that doesn't do anything
bool CCustomEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
if (eventType == "windows_generic_MSG")
{
MSG *pMsg = (MSG*)message;
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_SHIFT)
{
emit ShiftKeyDown();
}
}
else if (pMsg->message == WM_KEYUP)
{
if (pMsg->wParam == VK_SHIFT)
{
emit ShiftKeyUp();
}
}
}
return false;
}
#include<QAbstractNativeEventFilter>
#include <QObject>
class CCustomEventFilter : public QObject, public QAbstractNativeEventFilter
{
Q_OBJECT
public:
CCustomEventFilter(QObject *parent = 0);
~CCustomEventFilter();
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
signals:
void ShiftKeyDown();
void ShiftKeyUp();
};
.cpp file
#include "ccustomeventfilter.h"
#include "windows.h"
standard default constructor that doesn't do anything
bool CCustomEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
if (eventType == "windows_generic_MSG")
{
MSG *pMsg = (MSG*)message;
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_SHIFT)
{
emit ShiftKeyDown();
}
}
else if (pMsg->message == WM_KEYUP)
{
if (pMsg->wParam == VK_SHIFT)
{
emit ShiftKeyUp();
}
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
Then in my MainWindow program (CRat);
in CRat.h
#include "ccustomeventfilter"
CCustomEventFilter *m_pKeyFilter;
slots:
void OnKeyShiftDown();
void OnKeyShiftUp();
in CRat.cpp
in constructor
m_pKeyFilter = new CCustomEventFilter();
qApp->installNativeEventFilter(m_pKeyFilter);
connect(m_pKeyFilter, SIGNAL(ShiftKeyDown()), this, SLOT(OnKeyShiftDown()));
connect(m_pKeyFilter, SIGNAL(ShiftKeyUp()), this, SLOT(OnKeyShiftUp()));
in body of code
void CRat::OnKeyShiftDown()
{
set graph to vertical scroll
}
void CRat::OnKeyShiftUp()
{
set graph to horizontal scroll
}
in CRat.h
#include "ccustomeventfilter"
CCustomEventFilter *m_pKeyFilter;
slots:
void OnKeyShiftDown();
void OnKeyShiftUp();
in CRat.cpp
in constructor
m_pKeyFilter = new CCustomEventFilter();
qApp->installNativeEventFilter(m_pKeyFilter);
connect(m_pKeyFilter, SIGNAL(ShiftKeyDown()), this, SLOT(OnKeyShiftDown()));
connect(m_pKeyFilter, SIGNAL(ShiftKeyUp()), this, SLOT(OnKeyShiftUp()));
in body of code
void CRat::OnKeyShiftDown()
{
set graph to vertical scroll
}
void CRat::OnKeyShiftUp()
{
set graph to horizontal scroll
}
To copy to clipboard, switch view to plain text mode
I tried to find examples where a subclass native event filter sent out an event or something that could act on MainWindow objects (in my case, graph windows) but couldn't find any. All the examples I could find just showed how to print out a deBug() line when it hit the event you wanted. That doesn't tell me how to get it to do anything in the program I'm working from. This was the only way I could think of to make it either throw an event or emit a signal that MainWindow could use. It works, but there has GOT to be a prettier way to do it.
Anyway, without all your help d_stranz I would have never gotten it and I thank you from the bottom of my heart.
Tony
Bookmarks