PDA

View Full Version : catch (spaceBar+mouse move) event



prasad.ece2
28th November 2013, 15:04
hi,
i want to drag my scene, by dragging the mouse on scene & hold space bare (press and hold space bar + drag mouse) .
what is the best place to check this combination and how can i check this condition .
i have QGraphicsView and QGraphicsScene on QMainwindow .

my idea is as below

QGraphicsView:: mouseMoveEvent(QMouseEvent* f_event)
{

If(space bar is pressed and hold) // here how can I check key press event

{

Here we will set drag mode; //QGraphicsView:: ScrollHandDrag
}
}


Thanks in advance :-)

ChrisW67
29th November 2013, 04:54
Set a flag when you receive a keyPressEvent() for Qt::Key_Space.
Clear the flag when you get a keyReleaseEvent() for Qt::Key_Space.
If the flag is set when you enter the mouseMouseEvent()...

prasad.ece2
29th November 2013, 07:39
thank you ChrisW67 .

is there any other way to check only current event, rather than setting bool ?

ChrisW67
2nd December 2013, 08:33
No. The key press event is over by the time the mouse event occurs and there is no isKeyDownNow() function.

d_stranz
3rd December 2013, 03:24
i want to drag my scene, by dragging the mouse on scene & hold space bare (press and hold space bar + drag mouse) .

This is very strange behavior for a user interface. Why don't you do something that is more normal (and that you can test for in a mouse event) like Shift + mouse drag? You can use the QMouseEvent::modifiers() method to check for the shift key.