setCanvas blocks mouse movement on QtCanvasView
Hello, All !
I developed class,
Code:
class XGisCanvasView : public QtCanvasView
{
private:
Q_OBJECT
public:
XGisCanvasView
(QWidget *parent
=NULL);
virtual ~XGisCanvasView (void);
QPoint getPos
(void) const { return scr;
}
signals:
protected:
virtual void contentsMouseReleaseEvent
(QMouseEvent *e
);
virtual void contentsMouseDoubleClickEvent
(QMouseEvent *e
);
private:
QtCanvas* pCanvas;
};
wsview.cpp
Code:
XGisCanvasView
:: XGisCanvasView(QWidget *parent
/*=NULL*/) : QtCanvasView
(parent
), scr
(QPoint(0,
0)){
setMouseTracking ( true );
viewport()->setMouseTracking ( true );
int x = width();
int y = height();
if ( parent )
{
x = parent->width();
y = parent->height();
}
qDebug ("width = %d height = %d", x, y);
pCanvas = new QtCanvas ( );
qDebug ("QtCanvas init");
pCanvas->resize (x, y);
setCanvas( pCanvas );
qDebug ("QtCanvas set");
this->canvas()->update();
bool isTrace = hasMouseTracking();
bool isVTrace = viewport()->hasMouseTracking();
if ( isTrace )
qDebug ("Mouse tracking is on");
else
qDebug ("Mouse tracking is off");
if ( isVTrace )
qDebug ("Viewport Mouse tracking is on");
else
qDebug ("Viewport Mouse tracking is off");
}
After setCanvas() function variables isTrace and isVTrace are true, but event contentsMouseMoveEvent (QMouseEvent *e) does not generated.
If I comment setCanvas() function, all mouse movements are traced normally. Where is problem ?
Best regards,
Yuriy Rusinov.
Re: setCanvas blocks mouse movement on QtCanvasView
Are events with mouse button depressed still being fired?
Re: setCanvas blocks mouse movement on QtCanvasView
I don't know. Which way they have to be verified ?
Re: setCanvas blocks mouse movement on QtCanvasView
Press and hold your mouse button over the canvas view and move the cursor :)
Re: setCanvas blocks mouse movement on QtCanvasView
I pressed and holded mouse button on QtCanvasView, contentsMouseMoveEvent () is generated, but I have to generate this event without pressing mouse button.
Re: setCanvas blocks mouse movement on QtCanvasView
Quote:
Originally Posted by YuriyRusinov
but I have to generate this event without pressing mouse button.
Sure, but now we know the problem is with tracking and not with posting events.
Why do you reference the viewport() of the canvas view anyway? Where do you check that contentsMouseMoveEvent? On the viewport or on the view directly?
Re: setCanvas blocks mouse movement on QtCanvasView
I reference to the viewport() because some documentation on QtCanvasView examples and my thread in qt-interest recommend this. I check contentsMouseMoveEvent in my class directly, using qDebug("Contents Mouse move event"). When I move mouse without pressing button, qDebug does not out anything.
Re: setCanvas blocks mouse movement on QtCanvasView
You could try enabling the tracking again after you set the canvas. There is nothing in the setCanvas() source code which could directly cause such a misbehaviour, but maybe one of the methods which get called from there mess something up.
Re: setCanvas blocks mouse movement on QtCanvasView
Problem was solved by adding this->widget()->setMouseTrackine (true); and removing all others such instructions. Thanks a lot.