Results 1 to 3 of 3

Thread: Can not capture expected mouse move event from GraphicsItem::sceneEventFilter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    9
    Qt products
    Qt4

    Default Can not capture expected mouse move event from GraphicsItem::sceneEventFilter

    Hi Qt experts,

    I can not capture the expected mouse move event from GraphicsItem::sceneEvent().

    I rewrite David w drell's code of "Example of re-sizing a QGraphicsItem using Mouse events."

    The class StateBox inherits from QGraphicsPixmapItem and install the corner members that users can drag the corner to to-size the item.

    These corners have been installed and sceneEventFilter() watch them.

    class Corner : public QGraphicsItem {..}
    class StateBox : public QGraphicsPixmapItem { .. Corner* _corners[8]; ..};

    void StateBox::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
    .. _corners[i]->installSceneEventFilter(this); ..} // then item can watch corner event



    in the event watch filter - sceneEventFilter(QGraphicsItem *watched, QEvent* event),
    I monitor the mouse movement of the corner in the StateBox's coordinate

    Corner *corner = dynamic_cast<Corner*>(watched);
    ...
    QGraphicsSceneMouseEvent * mevent
    = dynamic_cast<QGraphicsSceneMouseEvent*>(event);

    if (event->type() == QEvent::GraphicsSceneMouseMove)
    // dump mevemt->pos();


    However, the mouse movement is very strange ..
    If I drag the bottom-right corner, the position seems located on StateBox's coordinate and corner's coordinate.

    Is it a normal behavior ?

    How can I get the corner's position always in StateBox's ?

    this is my code link
    StateBox StateBox

    this is the mouse moving data form corner 2 (the right-bottom corner)
    example2.png
    " QEvent == 156" corner 2 mousedown QPointF(1, 3) // ? corner' coordinate ?
    " QEvent == 155" corner 2 move QPointF(2, 3) // ? corner's coordinate ?
    " QEvent == 155" corner 2 move QPointF(88, 89) // statebox's coordinate
    " QEvent == 155" corner 2 move QPointF(4, 4) // ? corner's coordinate ?
    " QEvent == 155" corner 2 move QPointF(90, 90) // statebox's coordinate
    " QEvent == 155" corner 2 move QPointF(6, 7)
    " QEvent == 155" corner 2 move QPointF(91, 91)
    " QEvent == 155" corner 2 move QPointF(8, 8)
    " QEvent == 155" corner 2 move QPointF(93, 92)

    Can you help ? Thank you very much.
    Last edited by chiaminhsu; 26th April 2013 at 04:19.

Similar Threads

  1. Capture mouse event on QHeaderView
    By squidge in forum Qt Programming
    Replies: 10
    Last Post: 10th August 2012, 11:54
  2. Problem with QGraphicsScene mouse move event
    By Nesbit in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2012, 18:12
  3. Replies: 3
    Last Post: 7th January 2012, 08:38
  4. QSystemTrayIcon capture mouse hover event
    By alan in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2009, 19:42
  5. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26

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.