PDA

View Full Version : Custom scrolling of QGraphicsView



hb
12th August 2008, 10:10
As I have some additional constraints on it, I am trying to implement custom scrolling on a QGraphicsView. My implementation used to work on Windows, but on X11, I got some problems even for very basic scrolling.

When I catch the mouse-press-event or mouse-move-event, I store the event. On the next move then, I calculate a delta between those mouse positions, and set the values of the horizontal and vertical scroll bars accordingly.

The problem now is that when a scrollbar value changes, I get another mouse move event (as a result of the graphics view moving under the mouse), which is just inverse to the delta that I put onto the scrollbars. So as a result, no scrolling is done (except some flicker).

The following implementation of a mouse move event will result two "phantom" mouse move events for each "real" event (user actually moves the mouse). Those phantom events come from the two QAbstractSlider::setValue() calls.



void MyGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
QScrollBar *hBar = horizontalScrollBar();
QScrollBar *vBar = verticalScrollBar();
QPoint delta = event->globalPos() - lastMouseEvent.globalPos();
ensureSceneFillsView();

hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));
vBar->setValue(vBar->value() - delta.y());
storeMouseEvent(event);
lastMouseEvent.setAccepted(false);
event->accept();
}


How do I get scrolling to work properly?