[Qt-interest] Question regarding QTimer

Atlant Schmidt aschmidt at dekaresearch.com
Thu Mar 17 11:41:24 CET 2011


All:

  Someone please remind me of the status of "Orbit" (the
  mobility support for Qt); did it ever ship? Will it?

  It would have surely had, built-in with no extra work
  needed, the "long press" support that Vesa is looking for.

  Otherwise, the only other guess I'd offer at this point
  is the reminder that everything (more-or-less) passes
  through the Qt Event Queue so it might be that other
  events in the queue (such as a large number of mouse
  move events) might be delaying delivery of the timer
  expiry event.

                                        Atlant

________________________________
From: Vesa Shmuel Peltonen [mailto:vesashmuel at gmail.com]
Sent: Thursday, March 17, 2011 06:35
To: Anton Chernov
Cc: Atlant Schmidt; qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Question regarding QTimer

Hi Anton,

I'm sorry, but I didn't get your point. I'm receiving the mouse event fine to the widget that I want them, and I'm handling those and not propagating these events further. The problem that I'm facing is when user press mouse for long time inside the widget, I want to do something before user releases the mouse. The 1st thing that came to my mind, is to use Qtimer, and do the thing after timeout occurs, but the slot is called always only after the mouse is released.  Are you suggesting, that the timer behavior will be affected if events are propagated or something on that path?

Any other ideas how to achieve the functionality? I.e to do something after user holds mouse for certain time (without releasing it).

Thanks,
vesa
On Thu, Mar 17, 2011 at 12:18 PM, Anton Chernov <mechernov at gmail.com<mailto:mechernov at gmail.com>> wrote:

Ok, here are the highlights:

> Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released. A mouse event contains a special accept flag that indicates whether the receiver wants the event. You should call ignore() if the mouse event is not handled by your widget.
Make sure you call ignore in the custom widget. (Or QWidget::event() )

> Qt::WA_NoMousePropagation. Schould be off!

But if the worst case is the following:
> If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
Then maybe its worth reporting a bug.


2011/3/17 Vesa Shmuel Peltonen <vesashmuel at gmail.com<mailto:vesashmuel at gmail.com>>

Thanks guys for your help so far!

I'm checking the relevant object in the filter, and the filter is installed on a custom Qwidget.

Here are the relevant traces. As you can see, the timer slot is called only after the mouse is released. The timeout probably has happened before that, because it is called immediately after mouse release event (when non zero timeout is used).

[Qt Message] eventFilter: IN
[Qt Message] eventFilter: mouse press
[Qt Message] starting longpress timer with 0 timeout
[Qt Message] eventFilter: OUT

[Qt Message] eventFilter: IN
[Qt Message] eventFilter: mouse move
[Qt Message] eventFilter: OUT

[Qt Message] eventFilter: IN
[Qt Message] eventFilter: mouse move
[Qt Message] eventFilter: OUT

[Qt Message] eventFilter: IN
[Qt Message] eventFilter: mouse move
[Qt Message] eventFilter: OUT

[Qt Message] eventFilter: IN
[Qt Message] eventFilter: mouse release
[Qt Message] eventFilter: OUT

[Qt Message] longPressTimeOutSlot IN


On Wed, Mar 16, 2011 at 6:43 PM, Anton Chernov <mechernov at gmail.com<mailto:mechernov at gmail.com>> wrote:

Where is you filter installed? Make sure this widget gets the events.

By the way I would check if this is the right object in the params (*object) ... :) Installing this filter on qApp will cause you hell :)

2011/3/16 Vesa Shmuel Peltonen <vesashmuel at gmail.com<mailto:vesashmuel at gmail.com>>
Yes, I know :)
The timer is started only once, when mouse is pressed. I expected, that the timer will timeout after 150 ms even when the mouse is still down, but it is not.
So, the sequence is this:
1. Mouse press down
-> timer started (I tried even 0 with timeout)
2. Mouse hold down for long time
3. Mouse released
=> timeout slot is called only here (even with 0 timeout).

As I said, tried this only on S^3, maybe platform specific behavior?

Thanks again,
Vesa

On Wed, Mar 16, 2011 at 5:16 PM, Atlant Schmidt <aschmidt at dekaresearch.com<mailto:aschmidt at dekaresearch.com>> wrote:

Vesa:

  You know that QTimers are "retriggerable", right? That is,
  if you do an m_timer->start(150) multiple times, each
  within 150 ms of the previous one, the timer doesn't time-out
  until 150 ms after the *LAST* call to start().

  Perhaps you're getting more MouseButtonPress events
  than you think and they're re-triggering your timer? Maybe
  you can place some debugging print or some such in the
  path that start()s the timer?

                                      Atlant

________________________________
From: qt-interest-bounces+aschmidt=dekaresearch.com<http://dekaresearch.com>@qt.nokia.com<http://qt.nokia.com> [mailto:qt-interest-bounces+aschmidt<mailto:qt-interest-bounces%2Baschmidt>=dekaresearch.com<http://dekaresearch.com>@qt.nokia.com<http://qt.nokia.com>] On Behalf Of Vesa Shmuel Peltonen
Sent: Wednesday, March 16, 2011 10:39
To: qt-interest at qt.nokia.com<mailto:qt-interest at qt.nokia.com>
Subject: [Qt-interest] Question regarding QTimer

Hello all,

I've simple question. I'm trying to start a timer when mouse press event is received on eventfilter:

xxx::eventFilter(QObject *object, QEvent *event)

{



    if ( event->type() == QEvent::MouseButtonPress )

    {



           m_timer->start(150); // msec

...























It seems that the timer timeouts always only after the mouse is released, even if the mouse press is very long (many seconds).

Is this known behavior and is there way to overcome the problem? Is the system process blocking the application thread during the mouse press, so even if the timeout should have happen much earlier, the slot is called only after the mouse is released?

Btw, my environment is Qt 4.7.2 on S^3 device. I've not tested the behavior on other platforms.











Thanks,

Vesa


Click here<https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==> to report this email as spam.

________________________________
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.


_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com<mailto:Qt-interest at qt.nokia.com>
http://lists.qt.nokia.com/mailman/listinfo/qt-interest





________________________________
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110317/ba9f803e/attachment.html 


More information about the Qt-interest-old mailing list