[Qt-interest] Mouse Position on the screen
Álvaro Morais
alvarommorais at gmail.com
Thu May 28 22:26:46 CEST 2009
A Quinta 28 Maio 2009 21:07:53 Karol Krizka você escreveu:
> Hi,
> Try to call the function QCursor::pos() using a timer event. It should
> accomplish what you want/
>
> From documentation:
> QPoint QCursor::pos () [static]
>
> Returns the position of the cursor (hot spot) in global screen
coordinates.
>
> --
> Cheers,
> Karol Krizka
> http://www.krizka.net
>
> On Thu, May 28, 2009 at 9:30 PM, Álvaro Morais
<alvarommorais at gmail.com> wrote:
> > 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.
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
Thanks. It worked. I don't know how I missed this.
Of course it was not working because I was centering my attention on
capture mouse events, rather than the mouse position.
I was thinking that QCursor::pos() didn't register values outside the
window, but what I was missing was the event's that never occurred
outside the window.
One more time, thanks. I was all day on this.
More information about the Qt-interest-old
mailing list