开发者

QGraphicsView noobie question

开发者 https://www.devze.com 2023-01-12 01:42 出处:网络
Trying to add text to QGraphicsView: Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)

Trying to add text to QGraphicsView:

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

    QGraphicsScene scene;
    scene.addText("Hello, worl开发者_C百科d!");
    ui->graphicsView->setScene(&scene);
}

But when the project running, there is nothing on the QGraphicsView.


Your QGraphicsScene scene is a local variable and it is deleted immeadiately after the Widget's constructor has been executed.

Change the scene to a private member variable of the Widget class.

0

精彩评论

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