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 [EMAIL PROTECTED]

Reply via email to