klampt.vis.qtbackend module

class klampt.vis.qtbackend.QtBackend[source]

Backend implementation of OpenGL visualization using Qt. Usually hidden from the user.

To use as a standalone program: Set up your GLProgramInterface, call createWindow to construct new windows and setProgram to set the GLProgram used in that window. Then call run() to start the Qt main loop.

createWindow(name, parent=None)[source]
initialize(program_name)[source]
kill()[source]
run()[source]

Starts the main loop

class klampt.vis.qtbackend.QtGLWindow(name='OpenGL window', parent=None)[source]

Bases: PyQt5.QtOpenGL.QGLWidget

A basic OpenGL window using Qt. Should not be used directly, use the functions in QtBackend instead.

name

title of the window (only has an effect before calling run())

Type:str
width, height

width/height of the window in screen units. These are initialized from the GLProgram viewport on run(), but thereafter Qt manages them. After, the user must call resize(w,h) to change the dimensions.

Type:int
devwidth, devheight

width/height of the window in OpenGL device pixel units (Note that these may be different from the screen dimensions due to Retina displays)

Type:int
clearColor

the RGBA floating point values of the background color.

Type:list of 4 floats
add_action(hook, short_text, key, description=None)[source]

This is called by the user to add actions to the menu bar.

Parameters:
  • hook (function) – a python callback function, taking no arguments.
  • short_text (str) – the text shown in the menu bar
  • key (str) – a shortcut keyboard command (can be ‘k’ or ‘Ctrl+k’)
  • description (str, optional) – if provided, this is a tooltip that shows up when the user hovers their mouse over the menu item.
close()[source]

Qt thread should call close() after this widget should be closed down to stop any existing Qt callbacks.

do_idlesleep(duration)[source]
do_refresh()[source]
do_reshape(w, h)[source]
draw_text(point, text, size=12, color=None)[source]

Renders text at the given point (may be 2d or 3d). Frontend should call this to draw text in either the display or display_screen method.

Parameters:
  • point (list of floats) – either a 2d or 3d point at which to draw the text
  • text (str) – the text to draw
  • size (int, optional) – if given, it renders a font in the given size.
  • color (list of 3 floats or list of 4 floats) –
hide()[source]

Hides the window, if already shown

idlesleep(duration=inf)[source]

Externally callable. Sleeps the idle callback for t seconds. If t is not provided, the idle callback is slept forever

idlesleep_signal
initialize()[source]

Opens a window and initializes. Called internally, and must be in the visualization thread.

initializeGL()[source]
keyPressEvent(QKeyEvent)[source]
keyReleaseEvent(QKeyEvent)[source]
modifiers()[source]

Call this to retrieve modifiers. Called by frontend.

mouseMoveEvent(QMouseEvent)[source]
mousePressEvent(QMouseEvent)[source]
mouseReleaseEvent(QMouseEvent)[source]
paintGL()[source]
refresh()[source]

Externally callable. Requests a refresh of the window

refresh_signal
reshape(w, h)[source]

Externally callable. Reshapes the window

reshape_signal
resizeEvent(event)[source]

Called internally by Qt when Qt resizes the window

resizeGL(int, int)[source]
setParent(QWidget)[source]

QWidget.setParent(QWidget, Qt.WindowFlags)

setProgram(program)[source]

User will call this to set up the program variable

show()[source]

Restores from a previous hide call

sizeHint() → QSize[source]
klampt.vis.qtbackend.toGlutButton(button)[source]
klampt.vis.qtbackend.toModifierList(modifiers)[source]