[Qt-interest] Mouse Position on the screen

Karol Krizka kkrizka at gmail.com
Thu May 28 22:07:53 CEST 2009


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
>




More information about the Qt-interest-old mailing list