Ya, it was the scrollbars that interfered. After setting
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
verticalScrollBar()->disconnect();
horizontalScrollBar()->disconnect();
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
verticalScrollBar()->disconnect();
horizontalScrollBar()->disconnect();
To copy to clipboard, switch view to plain text mode
in the constructor, now I can scroll the view properly when dragging it with the mouse. This is the reimplementation of the ScrollHandDragMode:
void GraphicsViewWidget
::mousePressEvent(QMouseEvent *event
) {
setCursor(Qt::ClosedHandCursor);
}
void GraphicsViewWidget
::mouseMoveEvent(QMouseEvent *event
) {
QPoint mouseDiff
= (mouse
- lastMouse
);
lastMouse = mouse;
QPointF mappedMouseDiff
= mapToScene
(mouseDiff
) - mapToScene
(0,
0);
if (event->buttons() & (Qt::LeftButton | Qt::RightButton | Qt::MiddleButton))
{
translate(mappedMouseDiff.x(), mappedMouseDiff.y());
}
}
void GraphicsViewWidget
::mouseReleaseEvent(QMouseEvent *event
) {
unsetCursor();
}
void GraphicsViewWidget::mousePressEvent(QMouseEvent *event)
{
setCursor(Qt::ClosedHandCursor);
}
void GraphicsViewWidget::mouseMoveEvent(QMouseEvent *event)
{
QPoint mouse = event->pos();
QPoint mouseDiff = (mouse - lastMouse);
lastMouse = mouse;
QPointF mappedMouseDiff = mapToScene(mouseDiff) - mapToScene(0,0);
if (event->buttons() & (Qt::LeftButton | Qt::RightButton | Qt::MiddleButton))
{
translate(mappedMouseDiff.x(), mappedMouseDiff.y());
}
}
void GraphicsViewWidget::mouseReleaseEvent(QMouseEvent *event)
{
unsetCursor();
}
To copy to clipboard, switch view to plain text mode
It scrolls properly no matter how the scene is scaled. It doesn't include the scroll fade out feature yet, it will remain my secret.
Bookmarks