Results 1 to 20 of 22

Thread: How can both graphicsView and graphicsItem receive mousemoveEvent?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Quote Originally Posted by aamer4yu View Post
    You didnt pay to the WHILE part... am not clear what you want to do with items WHILE you are rubberbanding ?
    You still didn't catch what i mean. I mean that ,only when i remove the mouseMoveEvent(QMouseEvent *event) function in the class which inherit from QGraphicsView , then the rubberbandrect can be achieved.(The rubberband rect function was achieved through the way :reimplement mousePressEvent, mouseMoveEvent , mouseReleaseEvent function in the class which inherit from QGraphicsItem).
    If i don't remove the mousemoveEvent function in the class which inherit from QGraphicsView, then the rubberbandrect can't be achieved. Now i think the main reason is that the class which inherit from QGraphicsView has intercepted the mouse event before the class which inherit from the item.

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

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Quote Originally Posted by christina123y View Post
    I have looked up QGraphicsView::dragMode in the QT assitant.But i don't know how this can help me? I have written eventfilter in the QGraphicsItem class,but it does nothing. There still only mouse move position tracking,but can't draw a rubberband rect,not less than zoom in through select a rubberband rect
    It can handle rubberband selecting for you. No need to write a single line of code besides activating the proper drag mode.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    christina123y (17th March 2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Please note the following:
    A MouseEvent propagates at first to the item under the mouse.

    If you subclass the item and call QGraphicsItem::mouseXXXEvent(envent), it will be propagated further. If you don't do that, the event is seen as processed and "dies".
    But if you call the parent handler, then you will meet this event also in the scene and the view again.

    Regards,
    Olli

  5. The following user says thank you to olidem for this useful post:

    christina123y (17th March 2009)

  6. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Did you have a look at the example in Qt Demo ?
    You can refer it from here also .
    You can select items through rubberbanding. Look into the code how they did it.

  7. The following user says thank you to aamer4yu for this useful post:

    christina123y (17th March 2009)

  8. #5
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Quote Originally Posted by olidem View Post
    Please note the following:
    A MouseEvent propagates at first to the item under the mouse.

    If you subclass the item and call QGraphicsItem::mouseXXXEvent(envent), it will be propagated further. If you don't do that, the event is seen as processed and "dies".
    But if you call the parent handler, then you will meet this event also in the scene and the view again.

    Regards,
    Olli
    Oh, thank you very much!
    I think this will help me! because i didn't call QGraphicsItem::mouseXXXEvent(envent), so maybe the event is seen as processed and "dies",but i tried this ,but the rubberband rect hadn't been drawn and nothing do to the graph, except the mouse postion tracking .

    i will try again!
    And now i have remove all mousePressEvent,mouseMoveEvent,mouseReleaseEvent in the class which inherit from the QGraphicsItem.
    Then i write the code of zoom in through select a rubberband rect in the class which inherit from the QGraphicsView.At last ,the mouse postion tracking didn't colides with the selection of rubberband rect. and this resolve my problem.
    As aamer4yu's reply of #6, he said that
    "I dont think you have to go to items level for that. What you need to do is - catch mouse events in your scene / view. Draw the rubberband in mouse move events, and finally on mouse release event you capture a rect, from the mousepress(x,y) and mouserelease(x,y).
    Now you convert this rect in to scene rect, and call QGraphicsView::fitInView()
    Thats it, you are zoomed in :-) , and you only had to capture events in the view "

    He was right, i needn't have to go to the items level. both mouse position tracking and rubberband rect zoom can both be handed in the QGraphicsView level.

    but i still puzzled why the view class intercepted the mouse event before the item ?

  9. #6
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Quote Originally Posted by christina123y View Post
    but i still puzzled why the view class intercepted the mouse event before the item ?
    Because the item "lets them through" ? As long as you call QGraphicsItem::mouseXXXEvent, it will travel through, I think

  10. The following user says thank you to olidem for this useful post:

    christina123y (18th March 2009)

  11. #7
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Quote Originally Posted by olidem View Post
    Because the item "lets them through" ? As long as you call QGraphicsItem::mouseXXXEvent, it will travel through, I think
    Now i counter another problem, the class which inherit from QGraphicsItem can't be moved and seletable.
    and i have setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
    in it's constructor,but it still can move.(i also try to put setFlags of this item in any possible postion, but it still can't be moved)
    but i also add a ellipse item in the scene, howerver,the ellipse item can move.

    Why? I don't understand why this happen to this item?
    Wish anyone's help soonly !Thank you!

  12. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Are you overriding some events of the item you inherited from graphicsitem ?

    If yes, are you calling the base class QGraphicsItem methods from there ?

  13. #9
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How can both graphicsView and graphicsItem receive mousemoveEvent?

    Hi,

    I have very similar problem regarding this subject.

    I have a QGraphicsView and QGraphicsScene and some QGraphicsItem (as usual). For again to zoom upan a rubberband action I needed to reimplement mouse move event in QGraphicsView. Moreover, I also want to change the color of the item whenever mouse moves on the item. So it seemed I need to reimplement the mouse move event also in the QGraphicsItem. But I doesn't work. I also tried out eventFilter thing.

    Can anyone help me?

    Thanks in advance.

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.