HappyCoder
15th July 2015, 10:48
Hello,
i have two plots where i linked the xBottom Axis. I made a subclass PlotMagnifier from QwtPlotMagnifier
and create in base class to objects
PlotMagnifier *_magnifierPressure;
PlotMagnifier *_magnifierTemperature;
and add some signals and slots:
connect( _magnifierPressure, SIGNAL(outWheelEvent(QWheelEvent*)), _magnifierTemperature, SLOT(inWheelEvent(QWheelEvent*)));
connect( _magnifierTemperature, SIGNAL(outWheelEvent(QWheelEvent*)), _magnifierPressure, SLOT(inWheelEvent(QWheelEvent*)));
PlotMagnifier.h
class PlotMagnifier : public QwtPlotMagnifier
{
Q_OBJECT
public:
PlotMagnifier( QWidget *canvas );
~PlotMagnifier();
signals:
void outMousePressEvent( QMouseEvent *mouseEvent );
void outMouseMoveEvent( QMouseEvent *mouseEvent );
void outMouseReleaseEvent( QMouseEvent *mouseEvent );
void outWheelEvent( QWheelEvent *wheelEvent );
public slots:
void inMousePressEvent( QMouseEvent *mouseEvent );
void inMouseMoveEvent( QMouseEvent *mouseEvent );
void inMouseReleaseEvent( QMouseEvent *mouseEvent );
void inWheelEvent( QWheelEvent *wheelEvent );
private:
bool eventFilter(QObject *, QEvent *);
};
plotmagnifier.cpp
bool PlotMagnifier::eventFilter( QObject *object, QEvent *event )
{
if ( object && object == parent() )
{
switch ( event->type() )
{
case QEvent::MouseButtonPress:
{
emit outMousePressEvent( static_cast<QMouseEvent *>( event ) );
widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
break;
}
case QEvent::MouseMove:
{
emit outMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
break;
}
case QEvent::MouseButtonRelease:
{
emit outMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
break;
}
case QEvent::Wheel:
{
emit outWheelEvent( static_cast<QWheelEvent *>( event ) );
widgetWheelEvent( static_cast<QWheelEvent *>( event ) );
break;
}
case QEvent::KeyPress:
{
widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
break;
}
case QEvent::KeyRelease:
{
widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
break;
}
default:;
}
}
return QObject::eventFilter( object, event );
}
void PlotMagnifier::inWheelEvent( QWheelEvent *wheelEvent )
{
widgetWheelEvent( static_cast<QWheelEvent *>( wheelEvent ) );
}
// other voids deleted, but same structure like inWheelEvent
This way it doesn't matter in which plot i use the mouse wheel, the event
is forwarded to to other plot and visa versa via signal/slot and is working fine.
I found here some other solutions and hints from Uwe to use the
signal scaleDivChanged() of QwtScaleWidget.
I have now some questions:
1. Are there any advantages/disadvantages using the eventFilter like i do?
2. I applied a panner to each plot and it's working also for both plots.
I guess that's because the eventFilter is applied to the canvas, right?
3. I tried to use scaleDivChanged() but don't know the target slot? I guess i need
to create a slot where i use setScaleDiv, right?
Greetings
Stefan
i have two plots where i linked the xBottom Axis. I made a subclass PlotMagnifier from QwtPlotMagnifier
and create in base class to objects
PlotMagnifier *_magnifierPressure;
PlotMagnifier *_magnifierTemperature;
and add some signals and slots:
connect( _magnifierPressure, SIGNAL(outWheelEvent(QWheelEvent*)), _magnifierTemperature, SLOT(inWheelEvent(QWheelEvent*)));
connect( _magnifierTemperature, SIGNAL(outWheelEvent(QWheelEvent*)), _magnifierPressure, SLOT(inWheelEvent(QWheelEvent*)));
PlotMagnifier.h
class PlotMagnifier : public QwtPlotMagnifier
{
Q_OBJECT
public:
PlotMagnifier( QWidget *canvas );
~PlotMagnifier();
signals:
void outMousePressEvent( QMouseEvent *mouseEvent );
void outMouseMoveEvent( QMouseEvent *mouseEvent );
void outMouseReleaseEvent( QMouseEvent *mouseEvent );
void outWheelEvent( QWheelEvent *wheelEvent );
public slots:
void inMousePressEvent( QMouseEvent *mouseEvent );
void inMouseMoveEvent( QMouseEvent *mouseEvent );
void inMouseReleaseEvent( QMouseEvent *mouseEvent );
void inWheelEvent( QWheelEvent *wheelEvent );
private:
bool eventFilter(QObject *, QEvent *);
};
plotmagnifier.cpp
bool PlotMagnifier::eventFilter( QObject *object, QEvent *event )
{
if ( object && object == parent() )
{
switch ( event->type() )
{
case QEvent::MouseButtonPress:
{
emit outMousePressEvent( static_cast<QMouseEvent *>( event ) );
widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
break;
}
case QEvent::MouseMove:
{
emit outMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
break;
}
case QEvent::MouseButtonRelease:
{
emit outMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
break;
}
case QEvent::Wheel:
{
emit outWheelEvent( static_cast<QWheelEvent *>( event ) );
widgetWheelEvent( static_cast<QWheelEvent *>( event ) );
break;
}
case QEvent::KeyPress:
{
widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
break;
}
case QEvent::KeyRelease:
{
widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
break;
}
default:;
}
}
return QObject::eventFilter( object, event );
}
void PlotMagnifier::inWheelEvent( QWheelEvent *wheelEvent )
{
widgetWheelEvent( static_cast<QWheelEvent *>( wheelEvent ) );
}
// other voids deleted, but same structure like inWheelEvent
This way it doesn't matter in which plot i use the mouse wheel, the event
is forwarded to to other plot and visa versa via signal/slot and is working fine.
I found here some other solutions and hints from Uwe to use the
signal scaleDivChanged() of QwtScaleWidget.
I have now some questions:
1. Are there any advantages/disadvantages using the eventFilter like i do?
2. I applied a panner to each plot and it's working also for both plots.
I guess that's because the eventFilter is applied to the canvas, right?
3. I tried to use scaleDivChanged() but don't know the target slot? I guess i need
to create a slot where i use setScaleDiv, right?
Greetings
Stefan