QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | List of all members
QwtPlotAxisWheelInteraction Class Reference

Configurable wheel interaction for a single plot axis. More...

#include <qwt_plot_axis_wheel_interaction.h>

Inheritance diagram for QwtPlotAxisWheelInteraction:

Classes

class  PrivateData
 

Public Member Functions

 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.
 
QwtScaleWidgetscaleWidget ()
 Return the observed scale widget.
 
const QwtScaleWidgetscaleWidget () const
 Return the observed scale widget (const version)
 
QwtPlotplot ()
 Return the plot that owns the axis.
 
const QwtPlotplot () const
 Return the plot that owns the axis (const version)
 
QwtAxisId axisId () const
 Return the axis id.
 

Protected Member Functions

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.
 

Detailed Description

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:

// Plain wheel zooms XBottom at cursor; Ctrl+wheel pans it
// Customize: Shift+wheel zooms YLeft, plain wheel pans
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:

class CenterZoom : public QwtPlotAxisWheelInteraction {
public:
protected:
void wheelZoom(double factor, const QPoint&) override {
// Zoom centered on axis midpoint instead of cursor
const QwtScaleMap m = plot()->canvasMap(axisId());
const int mid = static_cast<int>((m.p1() + m.p2()) / 2);
QwtPlotAxisWheelInteraction::wheelZoom(factor, QPoint(mid, 0));
}
};
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()

Constructor & Destructor Documentation

◆ QwtPlotAxisWheelInteraction()

QwtPlotAxisWheelInteraction::QwtPlotAxisWheelInteraction ( QwtPlot plot,
QwtAxisId  axisId 
)
explicit

Constructor from plot and axis id.

Parameters
[in]plotThe plot that owns the axis
[in]axisIdThe 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]scaleWidgetThe 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

Member Function Documentation

◆ 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]objObject receiving the event (should be the scale widget)
[in]eventEvent
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
[in]eventWheel event
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]

QwtScaleWidget * QwtPlotAxisWheelInteraction::scaleWidget ( )

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]ontrue to enable, false to disable
See also
isEnabled(), eventFilter()

◆ setPanFactor()

void QwtPlotAxisWheelInteraction::setPanFactor ( int  pixelsPerStep)

Set the pan distance per wheel step.

Parameters
[in]pixelsPerStepNumber 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]modifiersKeyboard 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
[in]factorZoom factor
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]modifiersKeyboard 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]deltaPixelsPixel 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]factorZoom factor (>1 zoom in, <1 zoom out)
[in]cursorPosCursor position in canvas coordinates

◆ zoomFactor()

double QwtPlotAxisWheelInteraction::zoomFactor ( ) const

Return the zoom factor.

Returns
Zoom factor
See also
setZoomFactor()

◆ 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: