HI:

So another day another problem that I don't understand. I'm doing the whole drag the peg into a box thing. Looking at the examples I found that it was a nice idea to use the close and open hand during the dragging movement. Here is the code for the peg class:
Qt Code:
  1. #include "peg.h"
  2.  
  3. Peg::Peg(QColor col){
  4. color = col;
  5. ScaleFactor = 1;
  6. }
  7.  
  8. QRectF Peg::boundingRect() const {
  9. double Margin = 2;
  10. return QRectF(-Margin,-Margin,10*ScaleFactor + 2*Margin,10*ScaleFactor + 2*Margin);
  11. }
  12.  
  13. void Peg::setMoveable(bool move){
  14. setFlag(ItemIsMovable,move);
  15. }
  16.  
  17. void Peg::setScaleFactor(double rad){
  18. ScaleFactor = rad;
  19. }
  20.  
  21. void Peg::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
  22. painter->setPen(QPen(Qt::black));
  23. QRadialGradient gradient(3,3,9);
  24. gradient.setColorAt(0.0,Qt::white);
  25. gradient.setColorAt(0.7,color.lighter(120));
  26. gradient.setColorAt(1.0,color);
  27. painter->setBrush(gradient);
  28. painter->scale(ScaleFactor,ScaleFactor);
  29. painter->drawEllipse(0,0,10,10);
  30. }
  31.  
  32. void Peg::mousePressEvent(QGraphicsSceneMouseEvent *event){
  33. if (event->button() != Qt::LeftButton){
  34. event->ignore();
  35. return;
  36. }
  37. setCursor(Qt::ClosedHandCursor);
  38. }
  39.  
  40.  
  41. void Peg::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
  42. setCursor(Qt::OpenHandCursor);
  43. }
To copy to clipboard, switch view to plain text mode 

I added the thing and when I click it the hand effectively closes but a soon as I start to move the peg, the peg inmediately appears in coordinates (0,0) of the scene and it starts moving from there (mantaining the distance from where the item originally lied to the (0,0)), Other than that it actually moves and it stays where the item is when I let go of the mouse button (which is a ways off from where the close hand cursor is).

Again, I ask,anyone got any idea of what am I doing wrong?

Thanks for any help.