You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "YuriyRusinov" is male
  • "YuriyRusinov" started this thread

Posts: 8

Location: Russian Federation

Occupation: Space Academy named Mozhaiskiy

  • Send private message

1

Wednesday, April 19th 2006, 1:54pm

setCanvas blocks QtCanvasView mouse tracking

Hello, All !

I develop class

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
};


In constructor of this class I make setcanvas for this QtCanvasView subclass

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 ( this );
    qDebug ("QtCanvas init");
    pCanvas->resize (x, y);

    //QtCanvasView (&wcanv, parent);
    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 variables isTrace and isVTrace are true, but mouse movement does not trace, I have to press mouse button. If I comment setCanvas function, all mouse movements are traced normally. Where is problem ?
Best regards,
Yuriy Rusinov.

  • "YuriyRusinov" is male
  • "YuriyRusinov" started this thread

Posts: 8

Location: Russian Federation

Occupation: Space Academy named Mozhaiskiy

  • Send private message

2

Thursday, April 20th 2006, 8:37am

setCanvas blocks QtCanvasView mouse tracking [SOLVED]

Problem was solved by adding this->widget()->setMouseTracking ( true ); and remove all others mouse settings.
Best regards,
Yuriy Rusinov.