markmuetz
22nd May 2008, 14:32
I've subclassed the QGraphicsScene class into my own class, and tried to re-implement the method
QGraphicsScene::mousePressEvent(QGraphicsSceneMous eEvent *event)
so as I can do something interesting when the use clicks on the view (namely cause a QGraphicsItem object to appear). On running the code and clicking in the view though, this method is not called.
Here are the relevant parts of code (as I see them), can anybody tell me what I'm missing?
DiagramScene *scene = new DiagramScene();
graphicsView = new QGraphicsView(scene);
class DiagramScene : public QGraphicsScene
{
Q_OBJECT
public:
DiagramScene(QObject *parent = 0);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
};
DiagramScene::DiagramScene(QObject *parent)
: QGraphicsScene(parent)
{
}
void DiagramScene::mousePressEvent(QGraphicsSceneMouseE vent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
//do something here...
}
QGraphicsScene::mousePressEvent(QGraphicsSceneMous eEvent *event)
so as I can do something interesting when the use clicks on the view (namely cause a QGraphicsItem object to appear). On running the code and clicking in the view though, this method is not called.
Here are the relevant parts of code (as I see them), can anybody tell me what I'm missing?
DiagramScene *scene = new DiagramScene();
graphicsView = new QGraphicsView(scene);
class DiagramScene : public QGraphicsScene
{
Q_OBJECT
public:
DiagramScene(QObject *parent = 0);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
};
DiagramScene::DiagramScene(QObject *parent)
: QGraphicsScene(parent)
{
}
void DiagramScene::mousePressEvent(QGraphicsSceneMouseE vent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
//do something here...
}