【问题标题】:Using QGraphicsScene subclass with ui?将 QGraphicsScene 子类与 ui 一起使用?
【发布时间】:2010-08-24 00:52:10
【问题描述】:

我已经在 QGraphicsScene 子类中为 mousePressEvent() 实现了信号,但我不知道如何在 UI 中使用该类。我可以将 QGraphicsView 小部件添加到我的 UI,但是我如何访问 场景

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));

编辑:这是编译,但鼠标按下事件被忽略。我认为这是一个单独的问题,所以我发布了another question

【问题讨论】:

  • 我认为您的意思是 ...setScene(scene) 而不是 ´...setScene(scn)`?

标签: c++ qt qt4 qt-creator


【解决方案1】:

在您的示例中:使用您已有的 scene 指针:

connect(scene, SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint));

或者,如果您没有指针,请使用this function

connect(ui->graphicsView->scene(), SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint));

(未经测试,但我看不出它为什么不起作用)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 2015-10-09
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-19
    相关资源
    最近更新 更多