mooreaa
1st July 2008, 03:23
Hello,
I am looking for a way to modify the active dragmode based on key modifiers or mouse buttons.
By default, I want it to be RubberBandDrag.
When the space key is pressed or the middle mouse button is pressed I want it to go to ScrollHandDrag.
I tried overriding graphicsview's key press/release events to change the state when the space key is pressed. This works, but because of the keyrepeat, it ends up calling setDragMode over and over.
Is there a better way to do this?
Also using this method does not seem to work to switch to scroll mode on middle mouse button.
void MyGraphicsView::mousePressEvent(QMouseEvent *mouseEvent)
{
if(mouseEvent->button() == Qt::MidButton)
this->setDragMode( QGraphicsView::ScrollHandDrag );
QGraphicsView::mousePressEvent(mouseEvent);
}
I am looking for a way to modify the active dragmode based on key modifiers or mouse buttons.
By default, I want it to be RubberBandDrag.
When the space key is pressed or the middle mouse button is pressed I want it to go to ScrollHandDrag.
I tried overriding graphicsview's key press/release events to change the state when the space key is pressed. This works, but because of the keyrepeat, it ends up calling setDragMode over and over.
Is there a better way to do this?
Also using this method does not seem to work to switch to scroll mode on middle mouse button.
void MyGraphicsView::mousePressEvent(QMouseEvent *mouseEvent)
{
if(mouseEvent->button() == Qt::MidButton)
this->setDragMode( QGraphicsView::ScrollHandDrag );
QGraphicsView::mousePressEvent(mouseEvent);
}