QGLViewer keyboard shortcuts

The default QGLViewer keyboard behavior is fairly classical. The different shortcut keys can entirely be redefined by your application. See the keyboardAndMouse example for a practical illustration.

Default keyboard shortcuts

This table lists the QGLViewer functions that are associated with a default shortcut key.
Key Description Associated function Action
A Toggle the display of the world axis QGLViewer::toggleDrawAxis() DRAW_AXIS
G Toggle the display of the XY grid QGLViewer::toggleDrawGrid() DRAW_GRID
F Toggle the display of the Frame per Second QGLViewer::toggleDisplayFPS() DISPLAY_FPS
? Toggle the display of all the text QGLViewer::toggleEnableText() ENABLE_TEXT
S Toggle the stereo display. QGLViewer::toggleStereoDisplay() STEREO
H Calls a help function. QGLViewer::help() HELP
Esc Quit the application. qApp->quit EXIT
Space Switch between the FLY and REVOLVE camera mode. camera()->toggleMode() CAMERA_MODE
Return Start/stop the animation loop. QGLViewer::toggleAnimationMode() ANIMATION
Ctrl-S Open the save snapshot dialog box. QGLViewer::saveSnapshot() SAVE_SCREENSHOT
Alt-Return Toggle the full screen mode QGLViewer::toggleFullScreen() FULL_SCREEN
C Toggle the camera key frame path editor. toggleCameraPathEditor() EDIT_CAMERA_PATHS
Z Toggle z-buffer display. QGLViewer::toggleDisplayZBuffer() DISPLAY_Z_BUFFER
Arrows Move the camera (parallel to screen). camera()->frame()->translate() -
+ / - Increases (decreases) camera fly speed. setFlySpeed() -
F1-F12 Plays/Pauses camera key frame path (if defined)
Reset the path when Fx is quickly press twice.
camera()->playKeyFramePath(i)
camera()->resetKeyFramePath(i)
-
Alt+(F1-F12) Defines a new camera key frame for path 1..12.
Deletes the path when Fx is quickly press twice.
camera()->addKeyFrame(i)
camera()->deleteKeyFrame(i)
-

Use QGLViewer::setShortcutKey(Action, Key) and QGLViewer::setShortcutStateKey(Action, StateKey) if you want to redefine one of these keys (probably in your init() function). Action is defined by the ShortcutAction enum, as in the above table.

For example, this code defines Alt-M as the new qglviewer::Camera::toggleMode() shortcut, Q is the new exit shortcut key (state key unchanged) and z-buffer display shortcut is disabled:
void Viewer::init()
{
  setShortcutKey(QGLViewer::CAMERA_MODE, Qt::Key_M, Qt::AltButton);
  setShortcutKey(QGLViewer::EXIT, Qt::Key_Q);
  setShortcutKey(QGLViewer::DISPLAY_Z_BUFFER, 0);
}
You can retrieve the current shortcut key value with shortcutKey(Action) and shortcutStateKey(Action). Current bindings are displayed by the default help() function.

One might argue that too many keys are binded to the viewer shortcuts, leaving no key for the user's defined shortcuts. If you think that the binded actions are too complex and you want to forbid them, simple set 0 as the action shortcut key, as is done above. If you want to use one of the binded keys for one of your own function, optionally bind the original action to a new key and do as detailed below.

Key customization

If you want to define a new shortcut key for one of your own functions, overload the void QGLViewer::keyPressEvent(QKeyEvent *e) function:
void Viewer::keyPressEvent(QKeyEvent *e)
  {
    switch (e->key())
    {
      case Qt::Key_R : reset(); updateGL(); break;
      // and so on...
      default: QGLViewer::keyPressEvent(e);
    }
  }
See the keyboardAndMouse example for a practical illustration.

Camera path key bindings

The 12 KeyFrameInterpolator that are attached to the Camera are binded to the F1-F12 keys by default. The following bindings are defined: Quickly pressing Fx twice resets the interpolation: The camera path shortcut keys can be redefined using the following methods:

Valid XHTML 1.0! Valid CSS! Last modified on Friday, November 7, 2003.