[Qt-interest] How to get mouse cursor position from QEvent
Frederico Prado
famprado at terra.com.br
Mon Feb 22 19:23:43 CET 2010
Use
void YourQWidget::mouseMoveEvent(QMouseEvent *event)
{
emit posChanged(event->pos());
}
Be sure to initialize MainWindow with:
YourQWidget->setMouseTracking(true);
And then you can connect the signal anywhere you want.
I hope this helps.
Regards,
Fred
On Seg 22/02/10 14:38 , "Steven Chang" steven01 at ms3.hinet.net sent:
> Hi Ulf,
>
>
>
> Since the enterEvent() function only accepts QEvent, but cannot accept
> QMouseEvent.
>
> void QWidget::enterEvent ( QEvent * event )
>
> So I can only try to get mouse position from QEvent.
>
> I tried to use QMouseEvent instead of QEvent in enterEvent(), and it
> could
> pass compiler, but the function never be called in run time.
>
>
>
> Best Regards,
>
> Steven
>
>
>
> -----Original Message-----
>
> From: qt-interest-bounces
> @trolltech.com
> [mailto:qt-interest-bounces
> @trolltech.com] On Behalf Of Ulf-Alexander v.
> Ceumern-Lindenstjerna
>
> Sent: Tuesday, February 23, 2010 12:55 AM
>
> To: qt-intere
> st at trolltech.com
> Subject: Re: [Qt-interest] How to get mouse cursor position from QEvent
>
>
> Hi.
>
>
>
> I was just about to suggest casting the event to a QMouseEvent, when I
> saw that QWidget::enterEvent ( QEvent * event ) receives a plain
>
> "QEvent". Kind of strange, since this is an event triggered by mouse
>
> interaction. Is there a reason for it that I can't see?
>
>
>
> /Ulf
>
>
>
> > -----Original Message-----
>
> > From: qt-interest-bounces
> @trolltech.com [mailto:qt-interest-
> > bounces
> @trolltech.com] On Behalf Of Steven Chang
> > Sent: Monday, February 22, 2010 5:23 PM
>
> > To: qt-intere
> st at trolltech.com
> > Subject: [Qt-interest] How to get mouse cursor position from QEvent
>
> >
>
> > Dear Sir,
>
> >
>
> >
>
> >
>
> > I re-implement Qt QWidget's protected function "void enterEvent(QEvent
> > *event);".
>
> >
>
> > How can I get the enter point or mouse cursor position from the
>
> > parameter(*event) of enterEvent function?
>
> >
>
> > Thanks a lot!
>
> >
>
> >
>
> >
>
> > Best Regards,
>
> >
>
> > Steven
>
>
>
>
>
> _______________________________________________
>
> Qt-interest mailing list
>
> Qt-intere
> st at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
> _______________________________________________
>
> Qt-interest mailing list
>
> Qt-intere
> st at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
More information about the Qt-interest-old
mailing list