|
QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
|
Configurable wheel interaction for a single plot axis 更多...
#include <qwt_plot_axis_wheel_interaction.h>
类 | |
| class | PrivateData |
Public 成员函数 | |
| QwtPlotAxisWheelInteraction (QwtPlot *plot, QwtAxisId axisId) | |
| Constructor from plot and axis id | |
| QwtPlotAxisWheelInteraction (QwtScaleWidget *scaleWidget) | |
| void | setEnabled (bool on) |
| Enable or disable the interaction | |
| bool | isEnabled () const |
| Return whether the interaction is enabled | |
| void | setZoomModifiers (Qt::KeyboardModifiers modifiers) |
| Set keyboard modifiers for zoom mode | |
| Qt::KeyboardModifiers | zoomModifiers () const |
| Return the zoom modifiers | |
| void | setZoomFactor (double factor) |
| Set the zoom factor per wheel step | |
| double | zoomFactor () const |
| Return the zoom factor | |
| void | setPanModifiers (Qt::KeyboardModifiers modifiers) |
| Set keyboard modifiers for pan mode | |
| Qt::KeyboardModifiers | panModifiers () const |
| Return the pan modifiers | |
| void | setPanFactor (int pixelsPerStep) |
| Set the pan distance per wheel step | |
| int | panFactor () const |
| Return the pan factor in pixels | |
| QwtScaleWidget * | scaleWidget () |
| Return the observed scale widget | |
| const QwtScaleWidget * | scaleWidget () const |
| Return the observed scale widget (const version) | |
| QwtPlot * | plot () |
| Return the plot that owns the axis | |
| const QwtPlot * | plot () const |
| Return the plot that owns the axis (const version) | |
| QwtAxisId | axisId () const |
| Return the axis id | |
Protected 成员函数 | |
| virtual bool | eventFilter (QObject *obj, QEvent *event) override |
| Event filter for wheel events on the scale widget | |
| virtual bool | handleWheelEvent (QWheelEvent *event) |
| Handle a wheel event on the scale widget | |
| virtual void | wheelZoom (double factor, const QPoint &cursorPos) |
| Perform a zoom on the axis | |
| virtual void | wheelPan (int deltaPixels) |
| Perform a pan on the axis | |
Configurable wheel interaction for a single plot axis
QwtPlotAxisWheelInteraction installs an event filter on a QwtScaleWidget (the axis tick area) and provides two configurable wheel actions:
Unlike the built-in QwtPlotScaleEventDispatcher (which hardcodes wheel=zoom and requires the axis to be clicked/selected first), this class:
When the modifier matches zoom or pan, the event is consumed (return true) so the dispatcher does not also process it. When the modifier matches neither, the event is passed through to the dispatcher for default handling.
Typical usage:
Inheritance example:
|
explicit |
Constructor from plot and axis id
| [in] | plot | The plot that owns the axis |
| [in] | axisId | The axis to attach the interaction to |
The event filter is installed on the QwtScaleWidget for the given axis. The interaction is enabled by default.
Constructor from a scale widget
| [in] | scaleWidget | The axis scale widget to observe |
The plot and axis id are auto-derived from the scale widget's parent (which must be a QwtPlot) using QwtPlotScaleEventDispatcher::findAxisIdByScaleWidget().
Destructor
| QwtAxisId QwtPlotAxisWheelInteraction::axisId | ( | ) | const |
Return the axis id
|
overrideprotectedvirtual |
Event filter for wheel events on the scale widget
| [in] | obj | Object receiving the event (should be the scale widget) |
| [in] | event | Event |
|
protectedvirtual |
Handle a wheel event on the scale widget
The wheel delta is read via qwt::compat::wheelEventDelta() for Qt5/Qt6 compatibility. When the current modifiers match the zoom modifiers, wheelZoom() is called. When they match the pan modifiers, wheelPan() is called. Otherwise the event is passed through (return false) so the QwtPlotScaleEventDispatcher can handle it.
| [in] | event | Wheel event |
| bool QwtPlotAxisWheelInteraction::isEnabled | ( | ) | const |
| int QwtPlotAxisWheelInteraction::panFactor | ( | ) | const |
| Qt::KeyboardModifiers QwtPlotAxisWheelInteraction::panModifiers | ( | ) | const |
| QwtPlot * QwtPlotAxisWheelInteraction::plot | ( | ) |
Return the plot that owns the axis
| const QwtPlot * QwtPlotAxisWheelInteraction::plot | ( | ) | const |
Return the plot that owns the axis (const version)
| QwtScaleWidget * QwtPlotAxisWheelInteraction::scaleWidget | ( | ) |
Return the observed scale widget
| const QwtScaleWidget * QwtPlotAxisWheelInteraction::scaleWidget | ( | ) | const |
Return the observed scale widget (const version)
| void QwtPlotAxisWheelInteraction::setEnabled | ( | bool | on | ) |
Enable or disable the interaction
When enabled, an event filter is installed on the observed scale widget to intercept wheel events before they reach the QwtPlotScaleEventDispatcher. When disabled, the filter is removed and the dispatcher regains full control.
| [in] | on | true to enable, false to disable |
| void QwtPlotAxisWheelInteraction::setPanFactor | ( | int | pixelsPerStep | ) |
Set the pan distance per wheel step
| [in] | pixelsPerStep | Number of pixels to pan per wheel notch (default: 30) |
| void QwtPlotAxisWheelInteraction::setPanModifiers | ( | Qt::KeyboardModifiers | modifiers | ) |
Set keyboard modifiers for pan mode
When the wheel is rotated with these modifiers on the scale widget, the axis is panned. The default is Qt::ControlModifier.
| [in] | modifiers | Keyboard modifiers |
| void QwtPlotAxisWheelInteraction::setZoomFactor | ( | double | factor | ) |
Set the zoom factor per wheel step
Values > 1 zoom in (range shrinks), values < 1 zoom out (range expands). The default is 1.2. For multi-step wheels the factor is compounded: pow(zoomFactor, abs(delta/120)).
| [in] | factor | Zoom factor |
| void QwtPlotAxisWheelInteraction::setZoomModifiers | ( | Qt::KeyboardModifiers | modifiers | ) |
Set keyboard modifiers for zoom mode
When the wheel is rotated with these modifiers on the scale widget, the axis is zoomed. The default is Qt::NoModifier (plain wheel).
| [in] | modifiers | Keyboard modifiers |
|
protectedvirtual |
Perform a pan on the axis
Default implementation calls QwtPlot::panAxis() with the given pixel delta, then replotAll(). Auto-replot is temporarily disabled to avoid redundant repaints.
Override this method to customize pan behavior, e.g. invert direction or add momentum.
| [in] | deltaPixels | Pixel offset (positive = right/down, negative = left/up) |
|
protectedvirtual |
Perform a zoom on the axis
Default implementation calls QwtPlot::zoomAxis() with the given factor and cursor position, then replotAll(). Auto-replot is temporarily disabled to avoid redundant repaints.
Override this method to customize zoom behavior, e.g. zoom centered on the axis midpoint instead of the cursor position.
| [in] | factor | Zoom factor (>1 zoom in, <1 zoom out) |
| [in] | cursorPos | Cursor position in canvas coordinates |
| double QwtPlotAxisWheelInteraction::zoomFactor | ( | ) | const |
| Qt::KeyboardModifiers QwtPlotAxisWheelInteraction::zoomModifiers | ( | ) | const |