Qt-interest Archive, January 2007
Tracking the mouse move events
Message 1 in thread
Hello
I have two widgets, the mouse is pressed on the first one,
and the cursor is moved to the second without releasing.
What I need is to receive the mouse move events
in the second widget.
( I need to implement mouse selection over multiple pages )
Is it possible to achieve with Qt4?
I tried to call releaseMouse() for the first widget
during the mouse movements, but with no success.
Thanks
Dmitry.
--
[ signature omitted ]
Message 2 in thread
Dmitry Poplavsky wrote:
> Hello
>
> I have two widgets, the mouse is pressed on the first one,
> and the cursor is moved to the second without releasing.
>
> What I need is to receive the mouse move events
> in the second widget.
> ( I need to implement mouse selection over multiple pages )
>
> Is it possible to achieve with Qt4?
>
> I tried to call releaseMouse() for the first widget
> during the mouse movements, but with no success.
>
>
>
The above behavior is called mousegrabbing and in enforced by both Qt
and the native windowing system. Mouse grabbing is generally a good
idea since it allows the widgets to keep a nice click state machine and
the user can cancel a click easily. In The X11 version of Qt the mouse
grabbing is enforced first by the XServer, then in Qt's x11Event(), then
again in Qt's translateMouseEvent methods(). In other words, turning
mouse grabbing off is not the solution you are looking for.
You might want to try something like having a selection manager that is
filtering all mouse events on all your page widgets and have that
manager class use mapToGlobal(), widgetAt() and mapFromGlobal() to
manipulate the selections across the widgets.
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 3 in thread
Thursday 04 January 2007 19:56 Justin Noel wrote:
> Dmitry Poplavsky wrote:
> > Hello
> >
> > I have two widgets, the mouse is pressed on the first one,
> > and the cursor is moved to the second without releasing.
> >
> > What I need is to receive the mouse move events
> > in the second widget.
> > ( I need to implement mouse selection over multiple pages )
> >
> > Is it possible to achieve with Qt4?
> >
> > I tried to call releaseMouse() for the first widget
> > during the mouse movements, but with no success.
Why not just something like:
void Widget1::mouseMoveEvent(QMouseEvent* e) {
emit mouseMoveEventFromWidget1(e);
}
Just connect widget2 to this signal, and you should be done.
> The above behavior is called mousegrabbing and in enforced by both Qt
> and the native windowing system. Mouse grabbing is generally a good
> idea since it allows the widgets to keep a nice click state machine and
> the user can cancel a click easily.
It's also very dangerous, as described in the Qt docs (QWidget::grabMouse).
Bo.
--
[ signature omitted ]
Message 4 in thread
Hi,
I 'd also say you should not deactivate mouse grabbing.
You may pbly also send a mouse event from widget 1 to widget 2.
Somehing like :
Widget1::mouseMoveEvent() {
if(mouse over widget 2) {
// compute mouse coordinate relative to widget to
// build a new QMouseEvent
// send it to widget 2 immediatly by using
// QCoreApplication::sendEvent ( QObject * receiver, QEvent * event )
}
}
Widget2::mouseMoveEvent() {
// do your job !
}
In that case, though, Widget2::mouseMoveEvent() would be executed both when
WIdget1 sends and event, and when Qt generates a usual event for Widget2 .
Hence, using signals and slots as proposed Justin may be better.
Nicolas
Bo Thorsen wrote:
> Thursday 04 January 2007 19:56 Justin Noel wrote:
>> Dmitry Poplavsky wrote:
>> > Hello
>> >
>> > I have two widgets, the mouse is pressed on the first one,
>> > and the cursor is moved to the second without releasing.
>> >
>> > What I need is to receive the mouse move events
>> > in the second widget.
>> > ( I need to implement mouse selection over multiple pages )
>> >
>> > Is it possible to achieve with Qt4?
>> >
>> > I tried to call releaseMouse() for the first widget
>> > during the mouse movements, but with no success.
>
> Why not just something like:
>
> void Widget1::mouseMoveEvent(QMouseEvent* e) {
> emit mouseMoveEventFromWidget1(e);
> }
>
> Just connect widget2 to this signal, and you should be done.
>
>> The above behavior is called mousegrabbing and in enforced by both Qt
>> and the native windowing system. Mouse grabbing is generally a good
>> idea since it allows the widgets to keep a nice click state machine and
>> the user can cancel a click easily.
>
> It's also very dangerous, as described in the Qt docs
> (QWidget::grabMouse).
>
> Bo.
>
--
[ signature omitted ]
Message 5 in thread
Nicolas Castagne wrote:
> Hi,
>
> I 'd also say you should not deactivate mouse grabbing.
>
> You may pbly also send a mouse event from widget 1 to widget 2.
>
> Somehing like :
>
> Widget1::mouseMoveEvent() {
> if(mouse over widget 2) {
> // compute mouse coordinate relative to widget to
> // build a new QMouseEvent
> // send it to widget 2 immediatly by using
> // QCoreApplication::sendEvent ( QObject * receiver, QEvent * event )
> }
> }
>
> Widget2::mouseMoveEvent() {
> // do your job !
> }
>
>
> In that case, though, Widget2::mouseMoveEvent() would be executed both when
> WIdget1 sends and event, and when Qt generates a usual event for Widget2 .
>
> Hence, using signals and slots as proposed Justin may be better.
>
> Nicolas
>
>
> Bo Thorsen wrote:
>
>> Thursday 04 January 2007 19:56 Justin Noel wrote:
>>> Dmitry Poplavsky wrote:
>>>> Hello
>>>>
>>>> I have two widgets, the mouse is pressed on the first one,
>>>> and the cursor is moved to the second without releasing.
>>>>
>>>> What I need is to receive the mouse move events
>>>> in the second widget.
>>>> ( I need to implement mouse selection over multiple pages )
>>>>
>>>> Is it possible to achieve with Qt4?
>>>>
>>>> I tried to call releaseMouse() for the first widget
>>>> during the mouse movements, but with no success.
>> Why not just something like:
>>
>> void Widget1::mouseMoveEvent(QMouseEvent* e) {
>> emit mouseMoveEventFromWidget1(e);
>> }
>>
>> Just connect widget2 to this signal, and you should be done.
>>
>>> The above behavior is called mousegrabbing and in enforced by both Qt
>>> and the native windowing system. Mouse grabbing is generally a good
>>> idea since it allows the widgets to keep a nice click state machine and
>>> the user can cancel a click easily.
>> It's also very dangerous, as described in the Qt docs
>> (QWidget::grabMouse).
>>
>> Bo.
>>
Thank you for the answers, the solution was to
send mouse event in the parent widget to the child widget
at mouse position with corrected coordinates
with QCoreApplication::sendEvent().
All the children widgets process mouse events as usually,
except they ignore the even if the mouse position is outside of it
( otherwise the parent widget will not receive it ).
Thanks
Dmitry.
--
[ signature omitted ]