Hi:
I need I want implement a basic button because I'm building an application that only uses QGraphicsItems. I need one button so here is the code I wrote to get started:

Qt Code:
  1. Button::Button(int w, int h, QString cap){
  2. caption = cap;
  3. width = w;
  4. height = h;
  5. color.setRed(40);
  6. color.setGreen(40);
  7. color.setBlue(40);
  8. pen.setColor(color.lighter(130));
  9. pen.setWidth(2);
  10. }
  11.  
  12. QRectF Button::boundingRect() const{
  13. double margin = 2;
  14. return QRectF(0,0,width+margin,height+margin);
  15. }
  16.  
  17. void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
  18. Q_UNUSED(widget);
  19. if (option->state & QStyle::State_Sunken){
  20. qDebug() << "I'm being pressed";
  21. painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
  22. QBrush brush(color);
  23. painter->setPen(pen);
  24. painter->setBrush(brush);
  25. painter->drawRoundedRect(QRect(0,0,width,height),20.0,20.0,Qt::RelativeSize);
  26. }
  27. else{
  28. painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
  29. QBrush brush(color);
  30. painter->setPen(pen);
  31. painter->setBrush(brush);
  32. painter->drawRoundedRect(QRect(0,0,width,height),20.0,20.0,Qt::RelativeSize);
  33. }
  34. }
  35.  
  36. void Button::mousePressEvent(QGraphicsSceneMouseEvent *event){
  37. if (event->button() != Qt::LeftButton){
  38. event->ignore();
  39. return;
  40. }
  41. qDebug() << "press";
  42. QGraphicsItem::mousePressEvent(event);
  43. update();
  44. }
  45.  
  46. void Button::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
  47. qDebug() << "release";
  48. emit(clicked());
  49. QGraphicsItem::mouseReleaseEvent(event);
  50. }
To copy to clipboard, switch view to plain text mode 

The problem is that when I press the button all I get is the message "press" and I don't get "release" or the "I'm being pressed" message. I've compared it over and over to the elastic node's example and I can't find any differences that would make mine not work. What's even more bizarre I allready have another implemented class that also uses de the mouseRelease and mousePress events to change cursors and it works perfectly.

Any one has any idea of what I could be doing wrong?

Thanks for any help.