Results 1 to 4 of 4

Thread: Reimplementing The MousePressEvent for Graphics Item

  1. #1
    Join Date
    May 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Reimplementing The MousePressEvent for Graphics Item

    Hi,
    When I try to re-implement the mouse press event for a graphics item for which I had set the flag ItemIsMovable, I get some un-orderly behaviour.
    The code is pasted at : http://rafb.net/p/iTwlPj79.html

    Thanks in Advance!!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplementing The MousePressEvent for Graphics Item

    Could you be more precise, what is "some un-orderly behaviour"?

    PS. Next time post the code here instead of linking to external sites, please.
    J-P Nurmi

  3. #3
    Join Date
    May 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing The MousePressEvent for Graphics Item

    Ok!!
    I am posting the code here

    Qt Code:
    1. #ifndef __ITEM_H__
    2. #define __ITEM_H__
    3.  
    4. #include <QtGui>
    5. #include <Qt>
    6. #include <QGraphicsPolygonItem>
    7. #include <QGraphicsItem>
    8. #include <QGraphicsScene>
    9. #include <QPolygonF>
    10.  
    11.  
    12.  
    13.  
    14. class myitem : public QGraphicsPolygonItem
    15.  
    16. {
    17.  
    18.  
    19. public :
    20. static int left_mouse_button ;
    21. myitem(float x,float y,QGraphicsItem *parent =0 ,QGraphicsScene *scene = 0);
    22. QPolygonF mypolygon ;
    23.  
    24. protected :
    25. void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
    26. void mousePressEvent(QGraphicsSceneMouseEvent *mouseevent);
    27. // void keyPressEvent(QKeyEvent *keyevent);
    28.  
    29.  
    30. };
    31.  
    32.  
    33.  
    34. #endif // __ITEM_H__
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void myitem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
    2. {
    3. // if (mouseEvent->button() == Qt::LeftButton)
    4. // myitem::left_mouse_button = 0 ;
    5.  
    6.  
    7. QGraphicsItem::mouseReleaseEvent(mouseEvent);
    8.  
    9. }
    10.  
    11. void myitem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
    12. {
    13. // if (mouseEvent->button() == Qt::LeftButton)
    14. // myitem::left_mouse_button = 1 ;
    15. QGraphicsItem::mouseMoveEvent(mouseEvent);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    The first time I move the item , it moves but the next time it starts moving from (it feels to me) a random position closer to the point from where it should start and later it disappers though I do not have a single line where I call hide.
    I feel its got to do something with the flag. Couldnt find a clue
    Last edited by jpn; 25th May 2008 at 19:59. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplementing The MousePressEvent for Graphics Item

    I suppose that call to mouseMoveEvent() in your mousePressEvent() implementation is unintentional.
    J-P Nurmi

Similar Threads

  1. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37

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.