Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, April 2008
Re: QGraphicsView::moveMouseEvent is called more than needed by dragging


Message 1 in thread

Hi,

the problem still persists.
Or maybe I missed something ?

Regards,
Albert


Albert Zhykhar wrote:
> Andreas Aardal Hanssen wrote:
>> Albert Zhykhar wrote:
>>> When one presses mid. mouse button and moves the mouse cursor one 
>>> pixel at
>>> a time one gets 1-5 times mouseMoveEvent calls. The first time delta is
>>> calculated correctly. But all subsequently mouseMoveEvent calls delta=0.
>>> Is this a known issue?
>>
>> Hi, Albert. Yes, I think so. I think the problem is gone if you try a 
>> recent
>> snapshot. Please let me know if it persists (I was unable to reproduce 
>> the
>> problem myself).
>>
> 
> Hi Andreas,
> 
> the problem has not been gone. I think my explanation of what I meant
> dragging was not clear enough. So the code here.
> 
> Below you will find the modified main.cpp from collidingmice example. If 
> you
> replace the examples\graphicsview\collidingmice\main.cpp with this one and
> compile with Qt-4.3.4 and Qt-4.4.0-snapshot-20080305, and compare the both
> programs then you will see that with Qt-4.3.4 version one can drag the 
> scene
> by pressing the middle mouse button, but Qt-4.4.0 version behaves 
> differently
> (it's a bug or a feature :) ?).
> 
> And if one looks at the output, one sees that GraphicsView::mouseMoveEvent
> is called more than once at a time.
> 
> all the best,
> Albert
> 
> P.S. tested on Windows XP with Visual Studio 2005 only
> 
> 
> 
> **************************************************************************** 
> 
> 
> #include "mouse.h"
> 
> #include <QtGui>
> 
> #include <math.h>
> 
> static const int MouseCount = 7;
> 
> class GraphicsView : public QGraphicsView
> {
> public:
>   GraphicsView(QGraphicsScene* scene)
>     : QGraphicsView(scene)
>     , m_handScrolling(false)
>   {}
> 
> protected:
>   void mouseMoveEvent(QMouseEvent* event);
>   void mousePressEvent(QMouseEvent* event);
>   void mouseReleaseEvent(QMouseEvent* event);
> 
> private:
>   QPoint m_lastMousePos;
>   bool m_handScrolling;
> };
> 
> 
> void GraphicsView::mousePressEvent(QMouseEvent* event)
> {
>   qDebug() << "GraphicsView: mousePressEvent";
>   if ( event->button() == Qt::MidButton )
>   {
>     qDebug() << "GraphicsView: mousePressEvent:" << event->pos() << 
> mapFromGlobal(event->globalPos()) << event->globalPos();
>     m_lastMousePos = mapFromGlobal(event->globalPos());
>     m_handScrolling = true;
>     event->accept();
>     return;
>   }
>   QGraphicsView::mousePressEvent(event);
> }
> 
> 
> void GraphicsView::mouseReleaseEvent(QMouseEvent* event)
> {
>   qDebug() << "GraphicsView: mouseReleaseEvent";
>   if ( event->button() == Qt::MidButton )
>   {
>     m_handScrolling = false;
>     event->accept();
>     return;
>   }
>   QGraphicsView::mouseReleaseEvent(event);
> }
> 
> 
> void GraphicsView::mouseMoveEvent(QMouseEvent* event)
> {
>   qDebug() << "GraphicsView: mouseMoveEvent";
>   if ( m_handScrolling )
>   {
>     qDebug() << "GraphicsView: mouseMoveEvent:" << event->pos() << 
> mapFromGlobal(event->globalPos()) << event->globalPos();
>     QScrollBar* hBar = horizontalScrollBar();
>     QScrollBar* vBar = verticalScrollBar();
>     QPoint delta = mapFromGlobal(event->globalPos()) - m_lastMousePos;
>     hBar->setValue(hBar->value() + (qApp->isRightToLeft() ? delta.x() : 
> -delta.x()));
>     vBar->setValue(vBar->value() - delta.y());
>     m_lastMousePos = mapFromGlobal(event->globalPos());
>     event->accept();
>     return;
>   }
>   QGraphicsView::mouseMoveEvent(event);
> }
> 
> /*****************************************************************/
> 
> //! [0]
> int main(int argc, char **argv)
> {
>     QApplication app(argc, argv);
>     qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
> //! [0]
> 
> //! [1]
>     QGraphicsScene scene;
>     scene.setSceneRect(-300, -300, 600, 600);
> //! [1] //! [2]
>     scene.setItemIndexMethod(QGraphicsScene::NoIndex);
> //! [2]
> 
> //! [3]
>     for (int i = 0; i < MouseCount; ++i) {
>         Mouse *mouse = new Mouse;
>         mouse->setPos(::sin((i * 6.28) / MouseCount) * 200,
>                       ::cos((i * 6.28) / MouseCount) * 200);
>         scene.addItem(mouse);
>     }
> //! [3]
> 
> //! [4]
>     GraphicsView view(&scene);
>     view.setRenderHint(QPainter::Antialiasing);
>     view.setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
> //! [4] //! [5]
>     view.setCacheMode(QGraphicsView::CacheBackground);
>     
> //view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);  
> // because of Qt-4.3.x
>     view.setDragMode(QGraphicsView::NoDrag);
> //! [5] //! [6]
>     view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding 
> Mice"));
>     view.resize(400, 300);
>     view.show();
> 
>     return app.exec();
> }
> //! [6]

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 2 in thread

This message was cancelled from within Mozilla.

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 3 in thread

Hi,

the problem still persists in Qt-4.4_rc1.
Or maybe I missed something ?

Regards,
Albert



Albert Zhykhar wrote:
> Andreas Aardal Hanssen wrote:
>> Albert Zhykhar wrote:
>>> When one presses mid. mouse button and moves the mouse cursor one 
>>> pixel at
>>> a time one gets 1-5 times mouseMoveEvent calls. The first time delta is
>>> calculated correctly. But all subsequently mouseMoveEvent calls delta=0.
>>> Is this a known issue?
>>
>> Hi, Albert. Yes, I think so. I think the problem is gone if you try a 
>> recent
>> snapshot. Please let me know if it persists (I was unable to reproduce 
>> the
>> problem myself).
>>
> 
> Hi Andreas,
> 
> the problem has not been gone. I think my explanation of what I meant
> dragging was not clear enough. So the code here.
> 
> Below you will find the modified main.cpp from collidingmice example. If 
> you
> replace the examples\graphicsview\collidingmice\main.cpp with this one and
> compile with Qt-4.3.4 and Qt-4.4.0-snapshot-20080305, and compare the both
> programs then you will see that with Qt-4.3.4 version one can drag the 
> scene
> by pressing the middle mouse button, but Qt-4.4.0 version behaves 
> differently
> (it's a bug or a feature :) ?).
> 
> And if one looks at the output, one sees that GraphicsView::mouseMoveEvent
> is called more than once at a time.
> 
> all the best,
> Albert
> 
> P.S. tested on Windows XP with Visual Studio 2005 only
> 
> 
> 
> **************************************************************************** 
> 
> 
> #include "mouse.h"
> 
> #include <QtGui>
> 
> #include <math.h>
> 
> static const int MouseCount = 7;
> 
> class GraphicsView : public QGraphicsView
> {
> public:
>   GraphicsView(QGraphicsScene* scene)
>     : QGraphicsView(scene)
>     , m_handScrolling(false)
>   {}
> 
> protected:
>   void mouseMoveEvent(QMouseEvent* event);
>   void mousePressEvent(QMouseEvent* event);
>   void mouseReleaseEvent(QMouseEvent* event);
> 
> private:
>   QPoint m_lastMousePos;
>   bool m_handScrolling;
> };
> 
> 
> void GraphicsView::mousePressEvent(QMouseEvent* event)
> {
>   qDebug() << "GraphicsView: mousePressEvent";
>   if ( event->button() == Qt::MidButton )
>   {
>     qDebug() << "GraphicsView: mousePressEvent:" << event->pos() << 
> mapFromGlobal(event->globalPos()) << event->globalPos();
>     m_lastMousePos = mapFromGlobal(event->globalPos());
>     m_handScrolling = true;
>     event->accept();
>     return;
>   }
>   QGraphicsView::mousePressEvent(event);
> }
> 
> 
> void GraphicsView::mouseReleaseEvent(QMouseEvent* event)
> {
>   qDebug() << "GraphicsView: mouseReleaseEvent";
>   if ( event->button() == Qt::MidButton )
>   {
>     m_handScrolling = false;
>     event->accept();
>     return;
>   }
>   QGraphicsView::mouseReleaseEvent(event);
> }
> 
> 
> void GraphicsView::mouseMoveEvent(QMouseEvent* event)
> {
>   qDebug() << "GraphicsView: mouseMoveEvent";
>   if ( m_handScrolling )
>   {
>     qDebug() << "GraphicsView: mouseMoveEvent:" << event->pos() << 
> mapFromGlobal(event->globalPos()) << event->globalPos();
>     QScrollBar* hBar = horizontalScrollBar();
>     QScrollBar* vBar = verticalScrollBar();
>     QPoint delta = mapFromGlobal(event->globalPos()) - m_lastMousePos;
>     hBar->setValue(hBar->value() + (qApp->isRightToLeft() ? delta.x() : 
> -delta.x()));
>     vBar->setValue(vBar->value() - delta.y());
>     m_lastMousePos = mapFromGlobal(event->globalPos());
>     event->accept();
>     return;
>   }
>   QGraphicsView::mouseMoveEvent(event);
> }
> 
> /*****************************************************************/
> 
> //! [0]
> int main(int argc, char **argv)
> {
>     QApplication app(argc, argv);
>     qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
> //! [0]
> 
> //! [1]
>     QGraphicsScene scene;
>     scene.setSceneRect(-300, -300, 600, 600);
> //! [1] //! [2]
>     scene.setItemIndexMethod(QGraphicsScene::NoIndex);
> //! [2]
> 
> //! [3]
>     for (int i = 0; i < MouseCount; ++i) {
>         Mouse *mouse = new Mouse;
>         mouse->setPos(::sin((i * 6.28) / MouseCount) * 200,
>                       ::cos((i * 6.28) / MouseCount) * 200);
>         scene.addItem(mouse);
>     }
> //! [3]
> 
> //! [4]
>     GraphicsView view(&scene);
>     view.setRenderHint(QPainter::Antialiasing);
>     view.setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
> //! [4] //! [5]
>     view.setCacheMode(QGraphicsView::CacheBackground);
>     
> //view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);  
> // because of Qt-4.3.x
>     view.setDragMode(QGraphicsView::NoDrag);
> //! [5] //! [6]
>     view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding 
> Mice"));
>     view.resize(400, 300);
>     view.show();
> 
>     return app.exec();
> }
> //! [6]

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 4 in thread

Hi, Albert,

Albert Zhykhar wrote:
> Hi,
> the problem still persists in Qt-4.4_rc1.
> Or maybe I missed something ?

I still cannot reproduce this problem; I've tried on both X11 and Windows XP
with MSVC .NET2005, and I have verified that for every step I move the
mouse, the window system sends only one motion event, which becomes only
one mouse move event.

Are you using a hypersensitive gaming mouse / tablet or the like? These
devices are known to deliver many events even if only one results in the
cursor actually moving.

-- 
 [ signature omitted ] 

Message 5 in thread

Andreas Aardal Hanssen wrote:
> Hi, Albert,
> 
> Albert Zhykhar wrote:
>> Hi,
>> the problem still persists in Qt-4.4_rc1.
>> Or maybe I missed something ?
> 
> I still cannot reproduce this problem; I've tried on both X11 and Windows XP
> with MSVC .NET2005, and I have verified that for every step I move the
> mouse, the window system sends only one motion event, which becomes only
> one mouse move event.

Do you mean that you can run my example (collidingmice with overloaded
GraphicsView) at your site and you can drag the whole scene with the MIDDLE
mouse button?
We have a "rich application" and do need dragging behavior exactly with
the MIDDLE mouse button.

> 
> Are you using a hypersensitive gaming mouse / tablet or the like? These
> devices are known to deliver many events even if only one results in the
> cursor actually moving.

No, it's standard logitech infrared mouse.

All the best,
Albert

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 6 in thread

Albert Zhykhar wrote:
> Do you mean that you can run my example (collidingmice with overloaded
> GraphicsView) at your site and you can drag the whole scene with the
> MIDDLE mouse button?
> We have a "rich application" and do need dragging behavior exactly with
> the MIDDLE mouse button.

Yes, I do exactly that. I've tried with left, right, middle buttons ;-). I
get only one mouse event to the view for each mouse motion. Have you tried
on other machines or platforms?

-- 
 [ signature omitted ] 

Message 7 in thread

Andreas Aardal Hanssen wrote:
> Albert Zhykhar wrote:
>> Do you mean that you can run my example (collidingmice with overloaded
>> GraphicsView) at your site and you can drag the whole scene with the
>> MIDDLE mouse button?
>> We have a "rich application" and do need dragging behavior exactly with
>> the MIDDLE mouse button.
> 
> Yes, I do exactly that. I've tried with left, right, middle buttons ;-). I
> get only one mouse event to the view for each mouse motion. Have you tried
> on other machines or platforms?
> 

Just tried another Windows-XP - it's the same result :(
And with an old good ball mouse nothing changes.

Maybe to clarify again with the example:
as long as no button is pressed, moving the mouse generates exactly
one mouseMoveEvent pro pixel. But with the middle mouse button being
pressed I see 3-5 mouseMoveEvents in the output pro pixel.
The first one shows actually change in globalPos(), but the rest
mouseMoveEvents come with the same globalPos().

Any ideas would be appreciated

Thanks
Albert

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 8 in thread

Albert Zhykhar wrote:
> Just tried another Windows-XP - it's the same result :(
> And with an old good ball mouse nothing changes.
> Maybe to clarify again with the example:
> as long as no button is pressed, moving the mouse generates exactly
> one mouseMoveEvent pro pixel. But with the middle mouse button being
> pressed I see 3-5 mouseMoveEvents in the output pro pixel.
> The first one shows actually change in globalPos(), but the rest
> mouseMoveEvents come with the same globalPos().
> Any ideas would be appreciated

I don't know why it would happen for you, but here's something you can do to
check if it Qt or Windows that's sending those excessive events:

In qapplication_win.cpp, you'll find a function called 

bool QETWidget::translateMouseEvent(const MSG &msg)

around line 2800. You can insert debug info/a break point there to track
when Windows sends a mouse move event to Qt. Then you can compare that to
how many events are delivered to QGraphicsView::mouseMoveEvent. If the
match is 1-1, then the problem is outside Qt, but if it's 1:many, it's
inside Qt.

Andreas :-)

-- 
 [ signature omitted ] 

Message 9 in thread

Hello Andreas,

Andreas Aardal Hanssen wrote:
> I don't know why it would happen for you, but here's something you can do to
> check if it Qt or Windows that's sending those excessive events:
> 
> In qapplication_win.cpp, you'll find a function called 
> 
> bool QETWidget::translateMouseEvent(const MSG &msg)
> 
> around line 2800. You can insert debug info/a break point there to track
> when Windows sends a mouse move event to Qt. Then you can compare that to
> how many events are delivered to QGraphicsView::mouseMoveEvent. If the
> match is 1-1, then the problem is outside Qt, but if it's 1:many, it's
> inside Qt.
> 
> Andreas :-)
> 

I have found the same behavior on Linux, so Windows in itself can be eliminated.

So the result till now:

   - dragging with a mouse is Okay in Qt-4.3.x (both Windows/Linux,
     my modified collidingmice example, view.setDragMode(QGraphicsView::NoDrag))

   - dragging with a mouse doesn't function in Qt-4.4.x (both Windows/Linux
     my modified collidingmice example, view.setDragMode(QGraphicsView::NoDrag))

   - dragging (NATIVE) with left mouse button is Okay in Qt-4.4.x (both Windows/Linux,
     original collidingmice example, view.setDragMode(QGraphicsView::ScrollHandDrag))


Typical output I see from the modified collidingmice example (in Qt-4.4.0):
generated with
qDebug() << event->pos() << mapFromGlobal(event->globalPos()) << event->globalPos()

// Press mouse button
GraphicsView: mousePressEvent: QPoint(159,163) QPoint(161,165) QPoint(1038,839)

// Hold mouse button and move the mouse ONE pixel along X-axis to the origin
GraphicsView: mouseMoveEvent: QPoint(158,163) QPoint(160,165) QPoint(1037,839)
GraphicsView: mouseMoveEvent: QPoint(159,163) QPoint(161,165) QPoint(1038,839)
GraphicsView: mouseMoveEvent: QPoint(159,163) QPoint(161,165) QPoint(1038,839)

// Release mouse button
GraphicsView: mouseReleaseEvent


Maybe you could take a look at my modified collidingmice example once more and
give me a tip what was introduced by transition Qt-4.3.4 -> Qt-4.4.0 that
break our code ?

Thanks
Albert

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 10 in thread

Hi, Albert,

Albert Zhykhar wrote:
> I have found the same behavior on Linux, so Windows in itself can be
> 
> So the result till now:
>    - dragging with a mouse is Okay in Qt-4.3.x (both Windows/Linux,
>      my modified collidingmice example,
>      view.setDragMode(QGraphicsView::NoDrag))

I don't understand how this can work - when you set the view to NoDrag mode,
the scroll dragging is disabled. I've tried with 4.3 using NoDrag myself;
dragging does not work...

>    - dragging (NATIVE) with left mouse button is Okay in Qt-4.4.x (both

What does it mean to drag native?

If you can post all sources to your modified collidingmice example, maybe I
can reproduce it and help from there. I suspect there may be changes in
there that I'm not aware of ;-).

-- 
 [ signature omitted ] 

Message 11 in thread

Andreas Aardal Hanssen wrote:
> 
> If you can post all sources to your modified collidingmice example, maybe I
> can reproduce it and help from there. I suspect there may be changes in
> there that I'm not aware of ;-).
> 

Aaah! I see now.
Here is the complete source code of my modified collidingmice example.
Actually only main.cpp differs, that's why I published only this one
in my first(or second) post. The code works in Qt-4.3.4 as expected (dragging
with the middle mouse button being pressed).

Regards,
Albert

Attachment:

Attachment: collidingmice_modified.rar
Description: Binary data


Message 12 in thread

Hi again, Albert,

Albert Zhykhar wrote:
> Andreas Aardal Hanssen wrote:
>> If you can post all sources to your modified collidingmice example, maybe
>> I can reproduce it and help from there. I suspect there may be changes in
>> there that I'm not aware of ;-).
> Aaah! I see now.
> Here is the complete source code of my modified collidingmice example.
> Actually only main.cpp differs, that's why I published only this one
> in my first(or second) post. The code works in Qt-4.3.4 as expected
> (dragging with the middle mouse button being pressed).

I see the problem now; your code is triggering the mouse replay mechanism in
QGraphicsView. When you scroll or transform the view, if the mouse is over
the view, the view replays the mouse event to ensure that cursors and hover
states are kept up to date. When you drag, this doesn't work well because
the mouse position and scrolling delta are out of sync.

You can work around the problem by temporarily setting
QGraphicsView::setInteractive(false) while you're dragging (set it to false
in mousePressEvent() and true in mouseReleaseEvent()).

I've created a task for fixing this; in the mean time I hope the workaround
will be fine.

-- 
 [ signature omitted ] 

Message 13 in thread

Hi Andreas,

Andreas Aardal Hanssen wrote:
> Hi, Albert,
> 
> Albert Zhykhar wrote:
>> I have found the same behavior on Linux, so Windows in itself can be
>>
>> So the result till now:
>>    - dragging with a mouse is Okay in Qt-4.3.x (both Windows/Linux,
>>      my modified collidingmice example,
>>      view.setDragMode(QGraphicsView::NoDrag))
> 
> I don't understand how this can work - when you set the view to NoDrag mode,
> the scroll dragging is disabled. I've tried with 4.3 using NoDrag myself;
> dragging does not work...

I created a subclass of QGraphicsView and overloaded mouse{Press|Move|Release}Event
methods to implement custom dragging mechanism. So I set view.setDragMode(QGraphicsView::NoDrag)
and keep track of middle mouse button states. Please look at my GraphicsView class
in the example I posted earlier.

>>    - dragging (NATIVE) with left mouse button is Okay in Qt-4.4.x (both
> 
> What does it mean to drag native?

Native - I mean dragging with left mouse button implemented in QGraphicsView that works
of course when drag mode QGraphicsView::ScrollHandDrag is set.

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx