Configurable wheel interaction for a single plot axis.
More...
#include <qwt_plot_axis_wheel_interaction.h>
|
| 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:
- Zoom (plain wheel by default): zooms the axis centered at the cursor position using QwtPlot::zoomAxis().
- Pan (Ctrl+wheel by default): pans the axis by a fixed pixel amount per step using QwtPlot::panAxis().
Unlike the built-in QwtPlotScaleEventDispatcher (which hardcodes wheel=zoom and requires the axis to be clicked/selected first), this class:
- Supports keyboard modifiers to switch between zoom and pan.
- Works immediately without needing to select the axis first.
- Is fully configurable (modifiers, factors, enable/disable).
- Is designed for inheritance — override wheelZoom(), wheelPan(), or handleWheelEvent() to implement custom behavior.
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:
ix->setZoomModifiers(Qt::ShiftModifier);
ix->setPanModifiers(Qt::NoModifier);
Configurable wheel interaction for a single plot axis.
Definition qwt_plot_axis_wheel_interaction.h:81
QwtPlot * plot()
Return the plot that owns the axis.
Definition qwt_plot_axis_wheel_interaction.cpp:261
@ XBottom
X axis below the canvas.
Definition qwt_axis.h:51
@ YLeft
Y axis left of the canvas.
Definition qwt_axis.h:45
Inheritance example:
public:
protected:
void wheelZoom(double factor, const QPoint&) override {
const int mid =
static_cast<int>((m.
p1() + m.
p2()) / 2);
}
};
QwtPlotAxisWheelInteraction(QwtPlot *plot, QwtAxisId axisId)
Constructor from plot and axis id.
Definition qwt_plot_axis_wheel_interaction.cpp:63
virtual void wheelZoom(double factor, const QPoint &cursorPos)
Perform a zoom on the axis.
Definition qwt_plot_axis_wheel_interaction.cpp:363
A scale map.
Definition qwt_scale_map.h:44
Q_DECL_CONSTEXPR double p2() const noexcept
Return second border of paint interval.
Definition qwt_scale_map.h:79
Q_DECL_CONSTEXPR double p1() const noexcept
Return first border of paint interval.
Definition qwt_scale_map.h:77
- See also
- QwtPlotScaleEventDispatcher, QwtPlot::zoomAxis(), QwtPlot::panAxis()
◆ QwtPlotAxisWheelInteraction()
| QwtPlotAxisWheelInteraction::QwtPlotAxisWheelInteraction |
( |
QwtPlot * |
plot, |
|
|
QwtAxisId |
axisId |
|
) |
| |
|
explicit |
Constructor from plot and axis id.
- Parameters
-
| [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
- Parameters
-
| [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
◆ axisId()
| QwtAxisId QwtPlotAxisWheelInteraction::axisId |
( |
| ) |
const |
Return the axis id.
- Returns
- Axis identifier
◆ eventFilter()
| bool QwtPlotAxisWheelInteraction::eventFilter |
( |
QObject * |
obj, |
|
|
QEvent * |
event |
|
) |
| |
|
overrideprotectedvirtual |
Event filter for wheel events on the scale widget.
- Parameters
-
| [in] | obj | Object receiving the event (should be the scale widget) |
| [in] | event | Event |
- Returns
- true when the wheel event was handled (consumed), false otherwise
- See also
- handleWheelEvent()
◆ handleWheelEvent()
| bool QwtPlotAxisWheelInteraction::handleWheelEvent |
( |
QWheelEvent * |
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.
- Parameters
-
- Returns
- true if the event was handled, false if modifiers matched neither zoom nor pan mode
◆ isEnabled()
| bool QwtPlotAxisWheelInteraction::isEnabled |
( |
| ) |
const |
Return whether the interaction is enabled.
- Returns
- true when enabled, false otherwise
- See also
- setEnabled()
◆ panFactor()
| int QwtPlotAxisWheelInteraction::panFactor |
( |
| ) |
const |
Return the pan factor in pixels.
- Returns
- Pixels per wheel step
- See also
- setPanFactor()
◆ panModifiers()
| Qt::KeyboardModifiers QwtPlotAxisWheelInteraction::panModifiers |
( |
| ) |
const |
Return the pan modifiers.
- Returns
- Keyboard modifiers for pan mode
- See also
- setPanModifiers()
◆ plot() [1/2]
| QwtPlot * QwtPlotAxisWheelInteraction::plot |
( |
| ) |
|
Return the plot that owns the axis.
- Returns
- Pointer to the QwtPlot widget
◆ plot() [2/2]
| const QwtPlot * QwtPlotAxisWheelInteraction::plot |
( |
| ) |
const |
Return the plot that owns the axis (const version)
- Returns
- Const pointer to the QwtPlot widget
◆ scaleWidget() [1/2]
Return the observed scale widget.
- Returns
- Pointer to the scale widget
◆ scaleWidget() [2/2]
| const QwtScaleWidget * QwtPlotAxisWheelInteraction::scaleWidget |
( |
| ) |
const |
Return the observed scale widget (const version)
- Returns
- Const pointer to the scale widget
◆ setEnabled()
| 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.
- Parameters
-
| [in] | on | true to enable, false to disable |
- See also
- isEnabled(), eventFilter()
◆ setPanFactor()
| void QwtPlotAxisWheelInteraction::setPanFactor |
( |
int |
pixelsPerStep | ) |
|
Set the pan distance per wheel step.
- Parameters
-
| [in] | pixelsPerStep | Number of pixels to pan per wheel notch (default: 30) |
- See also
- panFactor()
◆ setPanModifiers()
| 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.
- Parameters
-
| [in] | modifiers | Keyboard modifiers |
- See also
- panModifiers()
◆ setZoomFactor()
| 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)).
- Parameters
-
- See also
- zoomFactor()
◆ setZoomModifiers()
| 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).
- Parameters
-
| [in] | modifiers | Keyboard modifiers |
- See also
- zoomModifiers()
◆ wheelPan()
| void QwtPlotAxisWheelInteraction::wheelPan |
( |
int |
deltaPixels | ) |
|
|
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.
- Parameters
-
| [in] | deltaPixels | Pixel offset (positive = right/down, negative = left/up) |
◆ wheelZoom()
| void QwtPlotAxisWheelInteraction::wheelZoom |
( |
double |
factor, |
|
|
const QPoint & |
cursorPos |
|
) |
| |
|
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.
- Parameters
-
| [in] | factor | Zoom factor (>1 zoom in, <1 zoom out) |
| [in] | cursorPos | Cursor position in canvas coordinates |
◆ zoomFactor()
| double QwtPlotAxisWheelInteraction::zoomFactor |
( |
| ) |
const |
◆ zoomModifiers()
| Qt::KeyboardModifiers QwtPlotAxisWheelInteraction::zoomModifiers |
( |
| ) |
const |
Return the zoom modifiers.
- Returns
- Keyboard modifiers for zoom mode
- See also
- setZoomModifiers()
The documentation for this class was generated from the following files: