QGLView ClassThe QGLView class extends QGLWidget with support for 3D viewing. More... #include <QGLView> Inherits: QWindow. This class was introduced in Qt 4.8. Public Types
Public Functions
Public Slots
Signals
Protected Functions
Reimplemented Protected Functions
Additional Inherited Members
Detailed DescriptionThe QGLView class extends QGLWidget with support for 3D viewing. NavigatingNavigation in 3D space is possible under keyboard and mouse control. Holding down the left mouse button and dragging it will rotate the camera() position around the object being viewed. Holding down the left mouse button and the Shift key pans the view in a plane without rotating the viewed object. Using the mouse wheel, the view can be zoomed in or out. If the system does not have a mouse wheel, then holding down the left mouse button and the Control key and moving the mouse up and down will also zoom in and out. On the keyboard, the left, right, up, and down keys can also be used to shift the camera() position around the object being viewed. Shift and Control modify keys the same way they modify the left mouse button above. Stereo viewing supportNote - Stereo viewing is experimental and unsupported. If the hardware supports stereo buffers, then each time the scene needs to be painted, QGLView renders it twice: first from the perspective of the left eye, and then from the perspective of the right eye. The separation between the eye positions is specified by QGLCamera::eyeSeparation(). If the eye separation is zero, then stereo viewing is disabled and only a single image will be rendered per frame. Three kinds of stereo viewing are possible: hardware stereo, anaglyph stereo, and double image stereo. Hardware stereo relies upon specialized hardware that can render the left and right eye images into separate buffers and then show them independently to each eye through the use of polarized glasses or similar technology. Hardware stereo is used if the -stereo-hw command-line option is supplied or if the user explicitly requests stereo buffers when the QGLView is constructed: QGLFormat format(QGLFormat::defaultFormat()); format.setOption(QGL::StereoBuffers); QGLView view(format); Anaglyph stereo is used when the hardware doesn't have specialized stereo buffer support. The left eye image is masked by a red filter and the right eye image is masked by a cyan filter. This makes the resulting images suitable for viewing with standard red-cyan anaglyph glasses. When using red-cyan anaglyphs, it is recommended that the scene use non-primary object colors. Pure primary colors such as red, green, and blue will only appear to one of the viewer's eyes and will inhibit the 3D effect. Non-primary colors or grayscale should be used to get the best effects. Red-cyan anaglyphs can be disorienting to some viewers. If hardware stereo is not available and stereo viewing is not critical to the application, then stereo can be disabled by setting QGLCamera::eyeSeparation() to zero. Double image stereo involves drawing the left and right eye images in a double-wide or double-high window, with the hardware combining the images. Four different configurations are available: LeftRight, RightLeft, TopBottom, and BottomTop, according to the layout of the eye images. Double image stereo is selected by calling setStereoType(). It is the responsibility of the application to resize the window to twice its normal size to accommodate the images. Ctrl-Left and Ctrl-Right can be used to make the eye separation smaller or larger under keyboard control. A number of command-line options are available to select the stereo mode of the QGLView so that the application does not need to select the mode itself:
The option can also be supplied in the QT3D_OPTIONS environment variable: $ QT3D_OPTIONS="-stereo-lr" ./cubehouse If the application sets the stereo type with setStereoType(), that will be used. Next is the command-line setting, and finally the contents of the environment variable. Member Type Documentation
flags QGLView::Options |
Constant | Value | Description |
---|---|---|
QGLView::ObjectPicking | 0x0001 | Object picking is enabled. Disabled by default. |
QGLView::ShowPicking | 0x0002 | Objects are rendered with their pick colors instead of their normal colors and materials. This can help debug problems with object picking. Disabled by default. |
QGLView::CameraNavigation | 0x0004 | Camera navigation using the keyboard and mouse is enabled. Enabled by default. |
QGLView::FOVZoom | 0x0010 | Enables zooming by changing field of view instead of physically moving the camera. |
The Options type is a typedef for QFlags<Option>. It stores an OR combination of Option values.
This enum defines the type of stereo viewing technology being used by QGLView.
Constant | Value | Description |
---|---|---|
QGLView::Hardware | 0 | Specialized stereo hardware is being used. |
QGLView::RedCyanAnaglyph | 1 | Stereo is being simulated for viewing by red-cyan anaglyph classes. |
QGLView::LeftRight | 2 | The view is double-wide with the left eye image on the left of the window. |
QGLView::RightLeft | 3 | The view is double-wide with the left eye image on the right of the window. |
QGLView::TopBottom | 4 | The view is double-high with the left eye image on the top of the window. |
QGLView::BottomTop | 5 | The view is double-high with the left eye image on the bottom of the window. |
QGLView::StretchedLeftRight | 6 | Same as LeftRight, but with the left and right eye images stretched to double their width. |
QGLView::StretchedRightLeft | 7 | Same as RightLeft, but with the left and right eye images stretched to double their width. |
QGLView::StretchedTopBottom | 8 | Same as TopBottom, but with the left and right eye images stretched to double their height. |
QGLView::StretchedBottomTop | 9 | Same as BottomTop, but with the left and right eye images stretched to double their height. |
Constructs a new view widget and attaches it to parent.
This constructor will request a stereo rendering context if the hardware supports it (and the -stereo-hw option is set).
Constructs a new view widget and attaches it to parent. The format argument specifies the desired QGLFormat rendering options.
If format does not include the stereo option, then a stereo viewing context will not be requested.
The format will be set onto the window, and also onto the underlying OpenGL context.
Destroys this view widget.
Returns the camera parameters. The camera defines the projection to apply to convert eye co-ordinates into window co-ordinates, and the position and orientation of the viewer's eye.
See also setCamera().
Returns the OpenGL context object associated with this view, or null if one has not been associated yet. The default is null.
Deregisters the object associated with objectId.
See also registerObject().
Performs early painting operations just after painter is initialized but before the camera is set up. The default implementation clears the color buffer and depth buffer.
This function is typically overridden to draw scene backdrops on the color buffer before the rest of the scene is drawn by paintGL().
See also paintGL().
Initializes the current GL context represented by painter.
See also paintGL().
Returns true if the view is visible, that is its show event has been called and was not followed by a hide event. Note that this cannot be relied apon for the visibility of the window, as it depends on whether hide and show events are triggered, which is platform dependent.
Reimplemented from QWindow::keyPressEvent().
Processes the key press event e.
Maps point from viewport co-ordinates to eye co-ordinates.
The returned vector will have its x and y components set to the position of the point on the near plane, and the z component set to the inverse of the camera's near plane.
This function is used for converting a mouse event's position into eye co-ordinates within the current camera view.
See also QGLCamera::mapPoint().
Reimplemented from QWindow::mouseDoubleClickEvent().
Processes the mouse double click event e.
Reimplemented from QWindow::mouseMoveEvent().
Processes the mouse move event e.
Reimplemented from QWindow::mousePressEvent().
Processes the mouse press event e.
Reimplemented from QWindow::mouseReleaseEvent().
Processes the mouse release event e.
Returns the registered object that is under the mouse position specified by point. This function may need to regenerate the contents of the pick buffer by repainting the scene with paintGL().
See also registerObject().
Returns the options for this view. The default value is CameraNavigation.
See also setOptions() and setOption().
Paints the scene onto painter. The color and depth buffers will have already been cleared, and the camera() position set.
If QGLPainter::isPicking() is set for painter, then the function should paint the scene onto painter in "object picking mode". The scene will be rendered into a background buffer using flat colors so that mouse events can determine which object lies under the mouse pointer.
The default implementation of picking will typically just render the scene normally. However, some applications may wish to render a simpler scene that omits unselectable objects and uses simpler meshes for the selectable objects.
The base default implementation does nothing. Sub-classes should re-implement this function to paint GL content.
See also earlyPaintGL().
Registers an object with this view to be notified when objectId is selected with the mouse. The object must persist for the lifetime of the QGLView, or until deregisterObject() is called for objectId.
See also deregisterObject() and objectForPoint().
Sets the camera parameters to value. The camera defines the projection to apply to convert eye co-ordinates into window co-ordinates, and the position and orientation of the viewer's eye.
If value is null, then the default camera object will be used.
This function will call update() to force the view to update with the new camera parameters upon the next event loop.
See also camera().
Enables or disables option according to value.
See also options() and setOptions().
Sets the options for this view to value.
See also options() and setOption().
Sets the type of stereo viewing technology that is in use. The request takes effect at the next repaint.
The request is ignored stereoType() or type is Hardware, because hardware stereo can only be enabled if the hardware supports it, and then it can never be disabled.
See also stereoType().
Returns the type of stereo viewing technology that is in use.
See also setStereoType().
Converts deltax and deltay into percentages of the view width and height. Returns a QPointF containing the percentage values, typically between -1 and 1.
This function is typically used by subclasses to convert a change in mouse position into a relative distance travelled across the field of view.
The returned value is corrected for the camera() screen rotation and view size.
This is an overloaded function.
Converts the x and y components of delta into percentages of the view width and height. Returns a QPointF containing the percentage values, typically between -1 and 1.
Reimplemented from QWindow::wheelEvent().
Processes the wheel event e.