QGLViewer keyboard actions

The default QGLViewer keyboard behavior is hopefuly intuitive. The different accelerator keys can entirely be redefined in your application and you can add new ones. See the keyboardAndMouse example for a practical illustration.

Default keyboard accelerators

This table lists the different KeyboardAction with their default accelerator keys.
KeyboardAction Key Description Associated function
DRAW_AXIS A Toggles the display of the world axis QGLViewer::toggleDrawAxis()
DRAW_GRID G Toggles the display of the XY grid QGLViewer::toggleDrawGrid()
DISPLAY_FPS F Toggles the display of the frame rate QGLViewer::toggleDisplayFPS()
ENABLE_TEXT ? Toggles the display of all the text QGLViewer::toggleEnableText()
STEREO S Toggles the stereo display QGLViewer::toggleStereoDisplay()
HELP H Displays a help window QGLViewer::help()
EXIT Escape Quits the application qApp->quit
CAMERA_MODE Space Switches between the FLY and REVOLVE camera mode camera()->toggleMode()
ANIMATION Return Starts/stops the animation loop QGLViewer::toggleAnimationMode()
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_PATHS C Toggles the camera key frame path editor toggleCameraPathEditor()
DISPLAY_Z_BUFFER Z Toggles z-buffer display QGLViewer::toggleDisplayZBuffer()
INCREASE_FLYSPEED
DECREASE_FLYSPEED
+ / - Increases or decreases the camera fly speed. camera()->setFlySpeed()
MOVE_CAMERA_LEFT
MOVE_CAMERA_RIGHT
MOVE_CAMERA_UP
MOVE_CAMERA_DOWN
Left, right
up and down
arrow keys
Moves the camera, parallel to the screen.
Displacement amplitude is proportionnal to flySpeed()
camera()->frame()->translate(...)
See setKeyFrameKey() and
setPlayKeyFramePathStateKey()
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)
See setKeyFrameKey() and
setAddKeyFrameStateKey()
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::setKeyboardAccelerator(Action, Key) to redefine one of these default accelerators (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 accelerator key disables the associated KeyboardAction:

void Viewer::init()
{
  // Press 'Q' to exit application
  setKeyboardAccelerator(EXIT, Key_Q);

  // Alt+M toggles camera mode
  setKeyboardAccelerator(CAMERA_MODE, ALT+Key_M);
  
  // Ctrl+Alt+Up moves the camera up
  setKeyboardAccelerator(MOVE_CAMERA_UP, CTRL+ALT+Key_Up);
  
  // The DISPLAY_Z_BUFFER action is disabled
  setKeyboardAccelerator(DISPLAY_Z_BUFFER, 0);
}
You can retrieve the current accelerator key value with keyboardAccelerator(Action). Current bindings are displayed in the help window "Keyboard" tab.

Binding new keyboard actions

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

      // Call the original method to handle other keys
      default: QGLViewer::keyPressEvent(e);
    }
  }
You should then use setKeyDescription() to add a short description of your keyboard accelerator in the help window Keyboard tab. See the keyboardAndMouse example for a practical illustration.

An other option is to bind an instance of a QAccel object to your viewer, thus enabling complex key sequences accelerators.

Camera paths keyboard accelerators

Each Camera holds 12 KeyFrameInterpolator, that are binded to the F1...F12 keys by default. The following bindings are defined: Quickly pressing Fx twice resets the interpolation: These camera path keyboard accelerators can be redefined using the following methods:

Valid XHTML 1.0! Valid CSS! Last modified on Wednesday, July 7, 2004.