I have implemented signals for mousePressEvent() in a QGraphicsScene subclass, but I can't figure out how to use the class in a UI. I can add a QGraphicsView widget to my UI, but how do I then access the scene?
GraphicsScene *scene = new QGraphicsScene(this);
// Add pixmap, etc
ui->graphicsView->setScene(scene);
// Here's where I'm stuck
connect(ui->whereIsTheScene?, SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint));
EDIT: This is compiling, but the mouse press event is being ignored. I think this is a开发者_JAVA百科 separate issue so I've posted another question
In your example: use the scene
pointer you already have:
connect(scene, SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint));
Alternatively, if you don't have the pointer laying around anymore, use this function:
connect(ui->graphicsView->scene(), SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint));
(untested, but I see no reason why it shouldn't work)
精彩评论