Also ich hab das mit dem QMouseEvent probiert, jedoch nicht hinbekommen.
Ich hab es nun anders probiert, aber ich finde einfach nicht heraus wie er auf die maus reagiert. Es kommt nur die leere Scene.
Ich stelle das Programm ma hier rein und hoffe jemand kann mir sagen was fehlt bzw. ob alles falsch ist

...
Code: Alles auswählen
class graphicView : public QGraphicsView
{
Q_OBJECT
public:
graphicView(QGraphicsScene* s);
~graphicView(){}
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
QRectF boundingRect() const;
private:
QGraphicsScene* scene;
QPoint *position;
int posx;
int posy;
protected:
void mousePressEvent( QMouseEvent* e );
};
Code: Alles auswählen
#include "graphicview.h"
graphicView::graphicView(QGraphicsScene* s)
:QGraphicsView(s), scene(s)
{
}
void graphicView::mousePressEvent( QMouseEvent* e )
{
if ( e->button() == Qt::LeftButton )
{
QPoint position = e->pos();
posx = position.x();
posy = position.y();
repaint(posx,posy, 100, 100);
}
QGraphicsView::mousePressEvent(e);
}
void graphicView::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
QPen pen(Qt::black, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
painter->setPen(pen);
painter->setRenderHint( QPainter::Antialiasing, true );
painter->drawPoint(posx,posy);
}
QRectF graphicView::boundingRect() const
{
return QRectF( 0, 0, 100, 100 );
}