Results 1 to 4 of 4

Thread: QCanvasView question

  1. #1
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default QCanvasView question

    Using: Qt 3.2.3

    Hi,

    I have a legacy app that defines a subclass of QCanvasView named DCanvasView. It is
    used as a viewing area in the QMainWindow derived class. DCanvasView defines
    its own contentsMouseMoveEvent method which changes the cursor shape to reflect current
    state (three different shapes) and display mouse coordinates in the status bar.

    My problem is that the cursor is changing when it enters the scroll bars; I only want it
    to change when it enter the viewport. (Actually, I used MS Spy++ and found that there is
    about a one-pixel frame-like border which is the parent (DCanvasView) window, and fully
    contained within it is the viewport, the two scroll bars, and the cornerWidget, and the
    cursor is changing when it is over that border, even prior to passing over the scrollbar.)

    contentsMouseMoveEvent only fires when the cursor enters the viewport area, so I am at a
    loss to explain where in the code the cursor is changing shape when it enters the non-
    viewport area of the CanvasView.

    Why is contentsMouseMoveEvent firing only when the cursor is in the viewport area? How
    can I handle mouse moves in the non-viewport area of the CanvasView?

    Thank you,
    Jim Brown

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

    Default Re: QCanvasView question

    Quote Originally Posted by JimBrown View Post
    Using: Qt 3.2.3
    You can mark that in your forum profile, so that you don't have to repeat that information in every thread.

    Why is contentsMouseMoveEvent firing only when the cursor is in the viewport area?
    Because it fires on the contents which is handled by the viewport and not by the whole widget.

    How
    can I handle mouse moves in the non-viewport area of the CanvasView?
    Reimplement mouse events for the view (like mouseMoveEvent) and not its contents (contentsMouseMoveEvent).

    I'm not sure if I understand your problem... First you write you want to handle only the viewport area and then you ask how to handle areas other than the viewport... If you want to adjust the cursor for the viewport, why not handle it through the viewport widget directly? You could reimplement enter and leave events for the viewport (or install an event filter) and use QWidget::setCursor to change the cursor for the viewport. Or you can probably do it without enter/leave events as well - after all, the cursor shape changes only when something actually happens in the scene, right?

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

    JimBrown (11th May 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default Re: QCanvasView question

    Although the app was using contentsMouseMoveEvent, the cursor was changing shape when it crossed the QCanvasView frame going from the outside into the widget. I never did figure out how or why that happened. So I thought that if I could capture the mouse move for the whole view (not just the viewport), I could explicitly change the cursor to the PointingHandCursor when it was outside of the viewport area (in other words, when it was over the scroll bars). Using mouseMoveEvent instead of contentsMouseMoveEvent did the trick. Thanks for the tip.

  5. #4
    Join Date
    Feb 2007
    Posts
    31
    Thanks
    11

    Default Re: QCanvasView question

    Here's the code I used in case it helps anyone...
    Qt Code:
    1. void MyCanvasView::mouseMoveEvent( QMouseEvent* e )
    2. {
    3. QPoint pos = e->pos();
    4. QRect vpr = viewport()->geometry();
    5.  
    6. if ( vpr.contains(pos)
    7. || ( pos.x() < 2 && pos.y() < vpr.bottom()) // view's left frame edge
    8. || ( pos.y() < 2 && pos.x() < vpr.right() )) // view's top frame edge
    9. {
    10. if ( pos.x() == vpr.right()
    11. || pos.y() == vpr.bottom() )
    12. {
    13. // I'm leaving the viewport and heading for a scrollbar
    14. setCursor( gloveCursor );
    15. }
    16. else
    17. {
    18. setCursor( forbiddenCursor );
    19. }
    20. }
    21. else
    22. {
    23. // I'm in the view but not the viewport; i.e. scrollbar area
    24. setCursor( gloveCursor );
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  2. QList question
    By aamer4yu in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2007, 13:43
  3. Replies: 1
    Last Post: 15th March 2007, 20:45
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  5. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38

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
  •  
Qt is a trademark of The Qt Company.