【问题标题】:QGraphicsView noobie questionQGraphicsView noobie 问题
【发布时间】:2010-08-14 12:36:31
【问题描述】:

尝试向 QGraphicsView 添加文本:

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    QGraphicsScene scene;
    scene.addText("Hello, world!");
    ui->graphicsView->setScene(&scene);
}

但是当项目运行时,QGraphicsView 上什么都没有。

【问题讨论】:

    标签: c++ qt qgraphicsview


    【解决方案1】:

    您的QGraphicsScene scene 是一个局部变量,它在Widget 的构造函数执行后立即被删除。

    将场景改为Widget类的私有成员变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 2011-01-09
      • 2021-11-25
      相关资源
      最近更新 更多