QGLViewer::camera()
, QGLViewer::manipulatedFrame()
orQGLViewer::mouseGrabber()
.
The actual behavior is entirely customizable: QGLViewer provides a list of atomic
ClickAction
that can be performed when you click, as well as a list of
MouseAction
that can be send to the camera
or the
manipulatedFrame
when you move. Any mouse button combination with any
Control, Alt, Shift
combination can be binded to any of these actions. Several
combinations can result in the same action.
The MouseGrabber
is specific since its behavior entirely depends on your implementation. See the MouseGrabber documentation page 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 associated default 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::clickAtion() . |
|
SELECT |
Calls the user-defined 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 out 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 position. |
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 |
Makes the camera go backward at flySpeed() and view direction can be changed. | |
SCREEN_ROTATE |
CAMERA |
Rotates with 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. | 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
indentical: 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 setMouseStateKey()
.
Also note that a double click basically automates the normal mouse action.
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.
Try the simpleViewer and manipulatedFrame examples for an illustration.
Note that for some QGLViewer::MouseAction
, the behavior slightly depends on the actual
handler (CAMERA
or FRAME
).
QGLViewer::mousePressEvent(QMouseEvent *e), mouseMoveEvent(), mouseDoubleClickEvent()
and mouseReleaseEvent()
functions. See the QGLViewer::mouseMoveEvent()
documentation for details.
Then, 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'll add it in the standard list.