0
我想繪製一個QMainWindow:到目前爲止,我已經建立了一個簡單的項目並在構造函數中輸入了一些代碼。 QGraphicsView顯示一個空白畫布。我還需要做些什麼來使我的圖紙可見?QGraphicsScence在添加表單後保持空白
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsScene scene(0,0,800,600);
this->view.setScene(&scene);
this->setCentralWidget(&view);
scene.addText("Hello, world!");
QPen pen(Qt::green);
scene.addLine(0,0,200,200,pen);
scene.addEllipse(400,300,100,100,pen);
//make a point:
double rad = 1;
scene.addEllipse(10-rad, 10-rad, rad*2.0, rad*2.0,pen,QBrush(Qt::SolidPattern));
scene.update();
view.show();
}
oooouuch。我認爲這個場景會保持活力,因爲我將它添加到視圖中。 – user2366975 2015-02-11 22:16:02
指向它的指針將保留,因爲你通過它,但實際的對象被銷燬。 Qt無法爲自動變量覆蓋C++內存管理。 – ftynse 2015-02-11 22:17:01