[Qt-interest] Mouse Position on the screen
Álvaro Morais
alvarommorais at gmail.com
Thu May 28 21:30:05 CEST 2009
Hi!
I'm developing an application that takes mouse Events to seed a (not
so)pseudo random generator.
While I can capture the mouse move on my application, the mouse
move is limited to the size of the widget.
Kpgen::Kpgen() :
QDialog()
{
...
// this enables all mouse events(and not just the clicked ones)
setMouseTracking(true);
}
// virtual void mouseMoveEvent ( QMouseEvent * event )
void Kpgen::mouseMoveEvent ( QMouseEvent * event )
{
std::cout << event->globalX() << ", " << event->globalY() <<
std::endl;
}
This works but as I said above only captures the mouse moves on the
widget.
What I want is to capture all mouse moves on the desktop, and not
just the mouse moves inside the widget.
I've tries QDesktopWidget like this:
QDesktopWidget *desktop = QApplication::desktop();
Well. This doesn't work since I want to capture the mouse events with
"virtual void mouseMoveEvent ( QMouseEvent * event )"
If I make a derivative class like this:
class desktopWidget : public QDesktopWidget
{
Q_OBJECT
public:
desktopWidget() : QDesktopWidget(*QApplication::desktop()) // or
something similar like desktopWidget(QDesktopWidget& _d) :
QDesktopWidget(_d)
{
setMouseTracking(true);
}
protected:
virtual void mouseMoveEvent ( QMouseEvent * event ) {
std::cout << event->globalX() << ", " << event->globalY() <<
std::endl;
}
};
This doesn't work since QDesktopWidget(const QDesktopWidget&;) is
private.
I've also tried installEventFilter on QDesktopWidget but it didn't work.
Last I've tried something like
class kpgenApp : public QApplication
{
Q_OBJECT
public:
kpgenApp( int & argc, char ** argv );
protected:
bool x11EventFilter ( XEvent * event );
};
But I've realized that X11 only sends events also inside the window.
Is any of this approaches the right one. If it is, what am I missing.
Thanks in advance for the trouble.
More information about the Qt-interest-old
mailing list