PDA

View Full Version : mouseMoveEvent not called when only move mouse (not drag) in QwtPlot



daxiong
9th May 2016, 13:32
In QwtPlot,I want to get current mouse position when I move mouse (not drag) in all the curve window areas.
I subclass a MainWindowMouseMoveEventTest from QMainWindow as curve window.
Then create a QwtPlot in MainWindowMouseMoveEventTest and set MainWindowMouseMoveEventTest as its parent,
then create a curve and a QwtLegend in QwtPlot , set MainWindowMouseMoveEventTest, QwtPlot and QwtPlot's canvas MouseTracking state true.
But when I move mouse to special areas like QwtLegend area and area beside scalar,the MainWindowMouseMoveEventTest's mouseMoveEvent is not called!!!
Unless I drag the mouse(press down and move) in this areas, the mouseMoveEvent is called.
Those special areas is marked by red circle in the screenshot:11931
I try to figure out the reason but failed, and I have search many solving method but failed .And this problem have been bothering me for several days.:(

My code:

#include "mainwindowmousemoveeventtest.h"

MainWindowMouseMoveEventTest::MainWindowMouseMoveE ventTest(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_pPlot = new QwtPlot(this);
QwtLegend* legnd = new QwtLegend;
m_pPlot->insertLegend(legnd, QwtPlot::TopLegend);

//curve
QwtPlotCurve *curve = new QwtPlotCurve("abc");
curve->attach(m_pPlot);


QwtAbstractLegend * pLegend = m_pPlot->legend();
pLegend->show();
////
setMouseTracking(true);
m_pPlot->setMouseTracking(true);
m_pPlot->canvas()->setMouseTracking(true);
//setCentralWidget(m_pPlot);
centralWidget()->setMouseTracking(true);

}

MainWindowMouseMoveEventTest::~MainWindowMouseMove EventTest()
{

}

void MainWindowMouseMoveEventTest::mouseMoveEvent( QMouseEvent * )
{

}

daxiong
11th May 2016, 07:56
I lookup the consist of qwtplot.
In my program its internal widget's area like this.11936
(But the yRight's area is not in the right edge of qwtplot?And I don't know which widget is in this right edge area.)

And use installEventFilter for its every internal widget (ex:canvas,legend,axes and ect).

MainWindowMouseMoveEventTest::MainWindowMouseMoveE ventTest(QWidget *parent)
: QMainWindow(parent)
{
...
centralWidget()->setMouseTracking(true);

setMouseTracking(true);
canvas->setMouseTracking(true);
canvas->installEventFilter(this);
....//other internal widgets also install
}

But there still is a area not responding.Shown in blue circle in the screenshot.

A solution is adding following code in MainWindowMouseMoveEventTest's constructor:
enableAxis( xRight, true );

But I don't want to show xRight axis.
So is there any other solution to it without showing xRight axis.
Any help will be appreciated!Thank u!

added: the mousemove event is responsed in virtual bool MainWindowMouseMoveEventTest::eventFilter(QObject * watched, QEvent * event);