Results 1 to 9 of 9

Thread: setCanvas blocks mouse movement on QtCanvasView

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default setCanvas blocks mouse movement on QtCanvasView

    Hello, All !

    I developed class,

    Qt Code:
    1. class XGisCanvasView : public QtCanvasView
    2. {
    3. private:
    4. Q_OBJECT
    5. public:
    6. XGisCanvasView (QWidget *parent=NULL);
    7. virtual ~XGisCanvasView (void);
    8.  
    9. QPoint getPos (void) const { return scr; }
    10.  
    11. signals:
    12. void contentsMouseMove (QMouseEvent *e);
    13. void mousePress (QMouseEvent *e);
    14. void mouseRelease (QMouseEvent *e);
    15. void mouseDoubleClick (QMouseEvent *e);
    16. void mouseContextMenu (QContextMenuEvent *e);
    17. void resize (QResizeEvent *e);
    18.  
    19. protected:
    20. virtual void contentsMouseMoveEvent (QMouseEvent *e);
    21. virtual void contentsMousePressEvent (QMouseEvent *e);
    22. virtual void contentsMouseReleaseEvent (QMouseEvent *e);
    23. virtual void contentsMouseDoubleClickEvent (QMouseEvent *e);
    24. virtual void contentsContextMenuEvent (QContextMenuEvent *e);
    25. virtual void resizeEvent (QResizeEvent *e);
    26.  
    27. private:
    28. QPoint scr;
    29. QtCanvas* pCanvas;
    30. };
    To copy to clipboard, switch view to plain text mode 

    wsview.cpp
    Qt Code:
    1. XGisCanvasView :: XGisCanvasView(QWidget *parent/*=NULL*/) : QtCanvasView (parent), scr (QPoint(0, 0))
    2. {
    3. setMouseTracking ( true );
    4. viewport()->setMouseTracking ( true );
    5.  
    6. int x = width();
    7. int y = height();
    8. if ( parent )
    9. {
    10. x = parent->width();
    11. y = parent->height();
    12. }
    13. qDebug ("width = %d height = %d", x, y);
    14. pCanvas = new QtCanvas ( );
    15. qDebug ("QtCanvas init");
    16. pCanvas->resize (x, y);
    17.  
    18. setCanvas( pCanvas );
    19. qDebug ("QtCanvas set");
    20. this->canvas()->update();
    21. bool isTrace = hasMouseTracking();
    22. bool isVTrace = viewport()->hasMouseTracking();
    23. if ( isTrace )
    24. qDebug ("Mouse tracking is on");
    25. else
    26. qDebug ("Mouse tracking is off");
    27. if ( isVTrace )
    28. qDebug ("Viewport Mouse tracking is on");
    29. else
    30. qDebug ("Viewport Mouse tracking is off");
    31. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setCanvas blocks mouse movement on QtCanvasView

    Are events with mouse button depressed still being fired?

  3. #3
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: setCanvas blocks mouse movement on QtCanvasView

    I don't know. Which way they have to be verified ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setCanvas blocks mouse movement on QtCanvasView

    Press and hold your mouse button over the canvas view and move the cursor

  5. #5
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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?

  7. #7
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  9. The following user says thank you to wysota for this useful post:

    YuriyRusinov (20th April 2006)

  10. #9
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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.

Similar Threads

  1. Game mouse movement
    By chaosgeorge in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2006, 23:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.