[Qt-interest] mouseReleaseEvent( ) of QGraphicsWidget

Alexei Sergeev alexeisergeev at gmail.com
Mon Mar 9 22:25:35 CET 2009


On Friday 12 December 2008 13:50:00 Bharath Narayan wrote:
> All,
> I am sub-classing QGraphicsWidget in my application and am trying to do
> something when mouse is released. I implemented mouseReleaseEvent( ) and
> when I debugged, I never got the mouse release event at all. Then I
> implemented mousePressEvent( ) too, in which case I got the events. I'm a
> little confused as to why would such a thing be needed? Is there a reason
> behind why a control should be given the Release event only if it accepts
> the Press event?

here is solution ( bug description that have solution in it (this was tested 
on Qt4.4:

AbstractElement::AbstractElement( AbstractElement *parent/*=0*/ )
: QGraphicsItem( parent )
{
   //!!!
   // Comment setFlag( ItemIsMovable, false );
   // to get mouse release!
   setFlag( ItemIsMovable, false );
}

AbstractElement::~AbstractElement()
{
}

void AbstractElement::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
   std::cerr<< "mouse press\n";
   //!!!
   // Comment QGraphicsItem::mousePressEvent( event ); 
   // to get mouse release!
   QGraphicsItem::mousePressEvent( event );
}


void AbstractElement::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
{
   //!!!
   // Called only if any of two lines I wrote about
   // commented.
   std::cerr<< "mouse release\n";
   QGraphicsItem::mouseReleaseEvent( event );
}



More information about the Qt-interest-old mailing list