[Qt-interest] System wide events
Poss3x
possex at web.de
Tue Aug 4 17:35:19 CEST 2009
Hi,
in my app I'd like to catch system wide events, especially mouse click
and mouse movement. System wide means that I do not want to capture the
events dispatched by my Qt app but in my case by Win32.
The present idea is to react on certain events in the system, especially
a drag event in explorer or desktop.
For the desktop I thought it would be easy to install an event filter
object in the application's desktop widget, like this:
class DesktopMouseListener : public QObject
{
public:
DesktopMouseListener(QObject * p) : QObject(p) {};
bool eventFilter(QObject * watched, QEvent * event)
{
if(event->type() == QEvent::MouseButtonPress)
{
QMouseEvent * me = (QMouseEvent*)event;
if(me->button() == Qt::LeftButton)
qDebug("desktop clicked...");
return true;
}
return false;
}
};
later installed like this:
QApplication::desktop()->installEventFilter(new DesktopMouseListener(this));
But this does not work as eventFilter(); it seems that desktop widget
does not handle "desktop clicks".
I also found in the API:
>>
bool QCoreApplication::winEventFilter ( MSG * msg, long * result ) [virtual]
The message procedure calls this function for every message received.
Reimplement this function if you want to process window messages msg
that are not processed by Qt. If you don't want the event to be
processed by Qt, then return true and set result to the value that the
window procedure should return. Otherwise return false.
It is only directly addressed messages that are filtered. To handle
system wide messages, such as messages from a registered hot key, you
need to install an event filter on the event dispatcher, which is
returned from QAbstractEventDispatcher::instance().
<<
So I installed an event filter on the event dispatcher, but it did not
work either. The left button press is only triggered when clicking
inside the app itself. But this is not what I want.
So my question:
Is there any solution to capture events like I described?
Thnx
More information about the Qt-interest-old
mailing list