Hi,
I have a PlotAxisPicker, maybe that help:
Header:
#ifndef PLOTAXISPICKER_H
#define PLOTAXISPICKER_H
// Qt
#include <QObject>
#include <QDebug>
#include <QEvent>
#include <QResizeEvent>
#include <QMouseEvent>
#include <QFrame>
// Qwt
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
class PlotAxisPicker
: public QObject{
Q_OBJECT
public:
explicit PlotAxisPicker
( QwtPlot::Axis axisId,
QwtPlot *plot
= nullptr
);
signals:
void doubleClickedLeft();
public slots:
private:
};
#endif // PLOTAXISPICKER_H
#ifndef PLOTAXISPICKER_H
#define PLOTAXISPICKER_H
// Qt
#include <QObject>
#include <QDebug>
#include <QEvent>
#include <QResizeEvent>
#include <QMouseEvent>
#include <QFrame>
// Qwt
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
class PlotAxisPicker : public QObject
{
Q_OBJECT
public:
explicit PlotAxisPicker( QwtPlot::Axis axisId, QwtPlot *plot = nullptr );
signals:
void doubleClickedLeft();
public slots:
private:
QwtScaleWidget *pScaleWidget;
bool eventFilter(QObject *, QEvent *event);
};
#endif // PLOTAXISPICKER_H
To copy to clipboard, switch view to plain text mode
CPP:
#include "plotaxispicker.h"
// Qt
#include <QDebug>
#include <QEvent>
#include <QMouseEvent>
// Qwt
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
{
pScaleWidget = plot->axisWidget( axisId );
pScaleWidget->setMouseTracking( true );
pScaleWidget->setFocusPolicy( Qt::NoFocus );
if ( pScaleWidget )
pScaleWidget->installEventFilter( this );
}
{
if (object
!= (QObject *)pScaleWidget
) {
return false;
}
if ( object
==(QObject *)pScaleWidget
) {
switch ( event->type() )
{
case QEvent::MouseButtonDblClick: {
if( mouseEvent->button()==Qt::LeftButton)
{
qDebug() << Q_FUNC_INFO << mouseEvent;
emit doubleClickedLeft();
}
break;
}
default:;
}
}
return QObject::eventFilter(object, event
);
}
#include "plotaxispicker.h"
// Qt
#include <QDebug>
#include <QEvent>
#include <QMouseEvent>
// Qwt
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
PlotAxisPicker::PlotAxisPicker( QwtPlot::Axis axisId, QwtPlot *plot) : QObject(plot)
{
pScaleWidget = plot->axisWidget( axisId );
pScaleWidget->setMouseTracking( true );
pScaleWidget->setFocusPolicy( Qt::NoFocus );
if ( pScaleWidget )
pScaleWidget->installEventFilter( this );
}
bool PlotAxisPicker::eventFilter(QObject *object, QEvent *event)
{
if (object != (QObject *)pScaleWidget )
{
return false;
}
if ( object==(QObject *)pScaleWidget )
{
const QMouseEvent *mouseEvent = (const QMouseEvent *)event;
switch ( event->type() )
{
case QEvent::MouseButtonDblClick:
{
if( mouseEvent->button()==Qt::LeftButton)
{
qDebug() << Q_FUNC_INFO << mouseEvent;
emit doubleClickedLeft();
}
break;
}
default:;
}
}
return QObject::eventFilter(object, event);
}
To copy to clipboard, switch view to plain text mode
In my subclass Plot (from QwtPlot)
pAxisXPicker
= new PlotAxisPicker
(QwtPlot::xBottom,
this);
pAxisYPicker
= new PlotAxisPicker
(QwtPlot::yLeft,
this);
pAxisXPicker = new PlotAxisPicker(QwtPlot::xBottom, this);
pAxisYPicker = new PlotAxisPicker(QwtPlot::yLeft, this);
To copy to clipboard, switch view to plain text mode
This is a workaround, because i need a double click on the axis title, but the axis title is not a QwtText Widget like the plot title or plot footer.
Guess the same problem like you, but you need the scaledraw and i'm not.
Bookmarks