camera()
, the manipulatedFrame()
or the mouseGrabber()
.
The actual behavior is entirely customizable: the ClickAction
(triggered when you
click) and the MouseAction
(activated when you click then drag) can be binded to any
mouse button(s) with any Control, Alt, Shift
modifier key combination.
Default bindings are described below. To sum up, the camera()
is the default mouse event
receiver while the manipulatedFrame()
is used when the Ctrl
key is pressed.
The MouseGrabber
is specific since its behavior entirely depends on your
implementation. See the MouseGrabber
documentation for details.
ClickAction
, use setMouseBinding(Qt::ButtonState, ClickAction,
doubleClick=false, buttonBefore=Qt::NoButton)
:
// Click on the right button to make a selection setMouseBinding(Qt::RightButton, SELECT); // Pressing the middle button, then double clicking the right button, while pressing Alt shows the entire scene. Cool huh ? setMouseBinding(Qt::AltButton | Qt::RightButton, SHOW_ENTIRE_SCENE, true, Qt::MidButton);
MouseAction
, use setMouseBinding(Qt::ButtonState, MouseHandler,
MouseAction, withConstraint=true)
(same function name as above, but different parameters):
// Left and right buttons together make a camera zoom : emulates a mouse third button if needed. setMouseBinding(Qt::LeftButton | Qt::RightButton, CAMERA, ZOOM); // Alt + Shift + Left button rotates the manipulatedFrame(). setMouseBinding(Qt::AltButton | Qt::ShiftButton | Qt::LeftButton, FRAME, ROTATE);
setWheelBinding(Qt::ButtonState, MouseHandler, MouseAction, withConstraint=true)
:
// Alt + wheel moves the camera forward. setWheelBinding(Qt::AltButton, CAMERA, MOVE_FORWARD);
The following tables list all the available ClickAction
and MouseAction
as
well as their default associated bindings. Note that the current bindings are always available in
the Mouse
tab of the help window (press H
for help).
ClickAction |
Description | Default binding |
ALIGN_CAMERA |
Align the camera axis with the world coordinate system axis. | Double click left button |
ALIGN_FRAME |
Align the manipulatedFrame() axis with the camera. |
Control + double click left button |
CENTER_FRAME |
Translates the manipulatedFrame() to the center of the screen. |
Control + double click right button |
CENTER_SCENE |
Translates the camera so that the sceneCenter is in the center of the screen. |
Double click right button |
NO_CLICK_ACTION |
No action, only used as a specific return value in QGLViewer::clickAction() . |
|
SELECT |
Calls the QGLViewer::select() function. |
Shift + Left button |
RAP_FROM_PIXEL |
Set the camera revolveAroundPoint() to the point under pixel (if any). |
Double click left button with right button pressed |
RAP_IS_CENTER |
Makes the sceneCenter the new camera revolveAroundPoint() . |
Double click right button with left button pressed |
SHOW_ENTIRE_SCENE |
Translates the camera so that the entire scene is visible. | Double click middle button |
ZOOM_ON_PIXEL |
Makes the camera zoom on the pixel under the mouse (if any). | Double click left button with middle button pressed |
ZOOM_TO_FIT |
Makes the camera zoom to see the entire scene. | Double click right button with middle button pressed |
MouseAction |
Handler |
Description | Default binding |
NO_MOUSE_ACTION |
No action, only used as a specific return value in QGLViewer::mouseAction() . |
||
ROTATE |
CAMERA |
Rotates the camera around its revolveAroundPoint() . |
Left button |
FRAME |
Rotates the manipulatedFrame() around its origin. |
Control + Left button | |
ZOOM |
CAMERA |
Makes the camera zoom in/out. Speed depends on distance to the scene center. | Middle button |
FRAME |
Makes the manipulatedFrame() move closer or further from the camera. | Control + Middle button | |
TRANSLATE |
CAMERA |
Translates in the camera XY plane. | Right button |
FRAME |
Control + Right button | ||
MOVE_FORWARD |
CAMERA |
Makes the camera go forward at flySpeed() and view direction can be changed. |
|
LOOK_AROUND |
CAMERA |
Change the viewing direction. The camera position is not modified. | |
MOVE_BACKWARD |
CAMERA |
Same as MOVE_FORWARD but backward. |
|
SCREEN_ROTATE |
CAMERA |
Rotates around an axis orthogonal to the screen. | Left and middle buttons |
FRAME |
Control + Left and middle buttons | ||
ROLL |
CAMERA |
Rolls camera according to horizontal mouse displacement. | Left and middle buttons (fly mode only) |
SCREEN_TRANSLATE |
CAMERA |
Translates purely horizontally or vertically on screen. | Middle and right buttons |
FRAME |
Control + Middle and right buttons | ||
ZOOM_ON_REGION |
CAMERA |
Draws a rectangular region on screen and zoom on it. | Shift + Middle button |
The CAMERA
and FRAME
default bindings are essentially
identical: You simply have to press the Control
state key to move the
FRAME
instead of the CAMERA
. This default state key can be
modified using setHandlerStateKey()
.
MOVE_FORWARD
, MOVE_BACKWARD
, LOOK_AROUND
and
ROLL
are specific to the CAMERA
fly mode. Press Space
to switch between revolve and fly camera modes.
mousePressEvent(),
mouseMoveEvent(), mouseDoubleClickEvent()
and mouseReleaseEvent()
callback
methods in your QGLViewer
derived class. See the
QGLViewer::mouseMoveEvent()
documentation for details.
Use QGLViewer::setMouseBindingDescription()
to add an entry in the help window
Mouse
tab that describes your new mouse binding.
See the keyboardAndMouse example for a practical implementation.
If you implemented a new mouse behavior and you think it can be useful for other applications, send me an e-mail and I will add it in the standard list.