Hallo, I'm a beginner and use Qt 4.4.3.
I would like to draw a point in a scene when i click in the scene. but my program draws a point without clicking, but the point should appear if i click.
I hope somebody can help me.
Here is my program:

Qt Code:
  1. class StarItem : public QGraphicsItem
  2. {
  3. public:
  4. StarItem( QGraphicsItem *parent = 0 ) : QGraphicsItem(parent) {}
  5. void paint( QPainter *, const QStyleOptionGraphicsItem *, QWidget *widget=0 );
  6. QRectF boundingRect() const;
  7. protected:
  8. void mousePressEvent(QGraphicsSceneMouseEvent *e);
  9. void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
  10. private:
  11. QPoint position;
  12. int posx;
  13. int posy;
  14. bool shower;
  15. };
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. #include "staritem.h"
  2.  
  3. void StarItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
  4. {
  5. if (e->button() == Qt::LeftButton)
  6. {
  7. shower=true;
  8. QPoint position = e->screenPos();
  9.  
  10. posx = position.x();
  11. posy = position.y();
  12. update();
  13. }
  14. return QGraphicsItem::mousePressEvent(e);
  15. }
  16.  
  17. void StarItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
  18. {
  19. position = e->screenPos();
  20. return QGraphicsItem::mouseMoveEvent(e);
  21. }
  22.  
  23.  
  24. void StarItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
  25. {
  26. Q_UNUSED( option );
  27. Q_UNUSED( widget );
  28.  
  29. QPen pen(Qt::black, 6, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
  30. painter->setPen(pen);
  31.  
  32. if(shower=true)
  33. {
  34. painter->drawPoint(posx,posy);
  35. }
  36.  
  37. }
  38.  
  39. QRectF StarItem::boundingRect() const
  40. {
  41. return QRectF( 0, 0, 100, 100 );
  42. }
To copy to clipboard, switch view to plain text mode 

I have no idea what's wrong...