HI!
I want to move a scene with mouse (left mouse button with CTRL). I use this code:
void GraphicsView
::mousePressEvent (QMouseEvent *event
) {
if (event->button () == Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
{
setInteractive (false);
_originX = event->x ();
_originY = event->y ();
}
else
{
}
}
{
if (event->buttons () & Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
{
QPointF oldp
= mapToScene
(_originX, _originY
);
QPointF newp
= mapToScene
(event
->pos
());
translate (translation.x (), translation.y ());
_originX = event->x ();
_originY = event->y ();
return;
}
}
void GraphicsView
::mouseReleaseEvent (QMouseEvent *event
) {
if (event->button () == Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
{
setInteractive (true);
}
else
{
}
}
void GraphicsView::mousePressEvent (QMouseEvent *event)
{
if (event->button () == Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
{
setDragMode (QGraphicsView::ScrollHandDrag);
setInteractive (false);
_originX = event->x ();
_originY = event->y ();
}
else
{
QGraphicsView::mousePressEvent (event);
}
}
void GraphicsView::mouseMoveEvent (QMouseEvent *event)
{
if (event->buttons () & Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
{
QPointF oldp = mapToScene (_originX, _originY);
QPointF newp = mapToScene (event->pos ());
QPointF translation = newp - oldp;
translate (translation.x (), translation.y ());
_originX = event->x ();
_originY = event->y ();
return;
}
QGraphicsView::mouseMoveEvent (event);
}
void GraphicsView::mouseReleaseEvent (QMouseEvent *event)
{
if (event->button () == Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
{
setDragMode (QGraphicsView::NoDrag);
setInteractive (true);
}
else
{
QGraphicsView::mouseReleaseEvent (event);
}
}
To copy to clipboard, switch view to plain text mode
And this code is not work.
Bookmarks