Keyboard shortcut customization

Default shortcut bindings are described below. They can be redefined in your application and you can add new ones. See the keyboardAndMouse example for a practical illustration.

Default keyboard shortcuts

This table lists the different KeyboardAction with their default shortcuts.
KeyboardAction Key Description Associated function
DRAW_AXIS A Toggles the display of the world axis QGLViewer::toggleAxisIsDrawn()
DRAW_GRID G Toggles the display of the XY grid QGLViewer::toggleGridIsDrawn()
DISPLAY_FPS F Toggles the display of the frame rate QGLViewer::toggleFPSIsDisplayed()
ENABLE_TEXT ? Toggles the display of all the text QGLViewer::toggleTextIsEnabled()
STEREO S Toggles the stereo display QGLViewer::toggleStereoDisplay()
HELP H Displays a help window QGLViewer::help()
EXIT_VIEWER Escape Quits the application qApp->quit
CAMERA_MODE Space Switches between the FLY and REVOLVE camera mode camera()->toggleCameraMode()
ANIMATION Return Starts/stops the animation loop QGLViewer::toggleAnimation()
SAVE_SCREENSHOT Ctrl+S Opens the save screenshot dialog box QGLViewer::saveSnapshot()
FULL_SCREEN Alt+Return Toggles the full screen mode QGLViewer::toggleFullScreen()
EDIT_CAMERA C Toggles the camera edition toggleCameraIsEdited()
+ / - Increases or decreases the camera fly speed. camera()->setFlySpeed()
Left, right
up and down
arrow keys
Moves the camera, parallel to the screen.
Displacement amplitude is proportional to flySpeed()
See pathKey() and
F1...F12 Plays/Pauses camera key frame path (if defined)
Reset the path when Fx is quickly press twice.
See pathKey() and
Alt+(F1...F12) Defines a new camera key frame for path 1..12.
Deletes the path when Fx is quickly press twice.

Use QGLViewer::setShortcut(Action, Key) to redefine one of these (probably in your init() function). Action is defined by the KeyboardAction enum, described in the above table, while Key is provided as an int using Qt enumerated values. Setting 0 as the shortcut key disables the associated KeyboardAction:

void Viewer::init()
  // Press 'Q' to exit application
  setShortcut(EXIT_VIEWER, Qt::Key_Q);

  // Alt+M toggles camera mode
  setShortcut(CAMERA_MODE, Qt::ALT | Qt::Key_M);
  // The DISPLAY_FPS action is disabled
  setShortcut(DISPLAY_FPS, 0);
You can retrieve the current shortcut with shortcut(Action). Current bindings are always available in the help window "Keyboard" tab.

Binding new keyboard actions

If you want to define a new keyboard shortcuts for one of your own methods, overload the QGLViewer::keyPressEvent(QKeyEvent *e) method:
void Viewer::keyPressEvent(QKeyEvent *e)
    switch (e->key())
      case Qt::Key_R : myResetMethod(); updateGL(); break;
      // and so on...

      // Default calls the original method to handle standard keys
      default: QGLViewer::keyPressEvent(e);
You should then use setKeyDescription() to add a short description of your keyboard shortcut in the help window. See the keyboardAndMouse example for a practical illustration.

Camera paths keyboard bindings

A Camera can have associated KeyFrameInterpolator that define paths and positions. The F1...F12 keys (noted Fx below) are binded to the Camera::keyFrameInterpolator() of indexes 1..12 by default. Quickly pressing Fx twice resets the interpolation: Use these methods to modify the camera path keyboard shortcuts:

Valid XHTML 1.0! Valid CSS! Last modified on Thursday, December 29, 2022.