PDA

View Full Version : setCanvas blocks mouse movement on QtCanvasView



YuriyRusinov
19th April 2006, 15:45
Hello, All !

I developed class,



class XGisCanvasView : public QtCanvasView
{
private:
Q_OBJECT
public:
XGisCanvasView (QWidget *parent=NULL);
virtual ~XGisCanvasView (void);

QPoint getPos (void) const { return scr; }

signals:
void contentsMouseMove (QMouseEvent *e);
void mousePress (QMouseEvent *e);
void mouseRelease (QMouseEvent *e);
void mouseDoubleClick (QMouseEvent *e);
void mouseContextMenu (QContextMenuEvent *e);
void resize (QResizeEvent *e);

protected:
virtual void contentsMouseMoveEvent (QMouseEvent *e);
virtual void contentsMousePressEvent (QMouseEvent *e);
virtual void contentsMouseReleaseEvent (QMouseEvent *e);
virtual void contentsMouseDoubleClickEvent (QMouseEvent *e);
virtual void contentsContextMenuEvent (QContextMenuEvent *e);
virtual void resizeEvent (QResizeEvent *e);

private:
QPoint scr;
QtCanvas* pCanvas;
};


wsview.cpp


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.

wysota
19th April 2006, 19:22
Are events with mouse button depressed still being fired?

YuriyRusinov
19th April 2006, 19:31
I don't know. Which way they have to be verified ?

wysota
19th April 2006, 19:32
Press and hold your mouse button over the canvas view and move the cursor :)

YuriyRusinov
19th April 2006, 19:41
I pressed and holded mouse button on QtCanvasView, contentsMouseMoveEvent () is generated, but I have to generate this event without pressing mouse button.

wysota
19th April 2006, 20:13
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?

YuriyRusinov
19th April 2006, 20:33
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.

wysota
19th April 2006, 21:51
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.

YuriyRusinov
20th April 2006, 08:38
Problem was solved by adding this->widget()->setMouseTrackine (true); and removing all others such instructions. Thanks a lot.