开发者

Using QGraphicsScene subclass with ui?

开发者 https://www.devze.com 2023-01-12 13:26 出处:网络
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

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消