View Full Version : Reimplementing The MousePressEvent for Graphics Item
ashishrai
25th May 2008, 20:35
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!! :)
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.
ashishrai
25th May 2008, 20:49
Ok!!
I am posting the code here
#ifndef __ITEM_H__
#define __ITEM_H__
#include <QtGui>
#include <Qt>
#include <QGraphicsPolygonItem>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QPolygonF>
class myitem : public QGraphicsPolygonItem
{
public :
static int left_mouse_button ;
myitem(float x,float y,QGraphicsItem *parent =0 ,QGraphicsScene *scene = 0);
QPolygonF mypolygon ;
protected :
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
void mousePressEvent(QGraphicsSceneMouseEvent *mouseevent);
// void keyPressEvent(QKeyEvent *keyevent);
};
#endif // __ITEM_H__
void myitem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
// if (mouseEvent->button() == Qt::LeftButton)
// myitem::left_mouse_button = 0 ;
QGraphicsItem::mouseReleaseEvent(mouseEvent);
}
void myitem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
// if (mouseEvent->button() == Qt::LeftButton)
// myitem::left_mouse_button = 1 ;
QGraphicsItem::mouseMoveEvent(mouseEvent);
}
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 :(
I suppose that call to mouseMoveEvent() in your mousePressEvent() implementation is unintentional. :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.