PDA

View Full Version : DragMode switching based on key & mouse button?



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);
}

robertson1
1st July 2008, 11:42
Hello,

setDragMode(QGraphicsView::ScrollHandDrag),only turns this mode on and off (its still left mouse button to drag), If setDragMode was set to something else before and you middle click then for your example it will then scroll hand drag whenever you click and hold the left mouse button after that.

I'm having a similar problem trying to drag with the middle mouse button. I reimplemented mouse press, move, release events to achieve something similar to scroll hand drag example code here:

http://www.qtcentre.org/forum/f-qt-programming-2/t-graphicsviewgraphicsscene-does-not-update-14057.htm

This worked ok up until QT4.4, now it soesnt work properly for some reason :confused: