Reputation: 85
I am new to Qt. I got a problem. I do not want to use Qt forms to create QGprahics view I just want to code it and I can't get it work.
here is my code:
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
scene = new QGraphicsScene(this);
scene->setSceneRect(600,480,600,480);
QGraphicsEllipseItem * ellipse;
QPen pen(Qt::red);
QBrush brush(Qt::blue);
ellipse = scene->addEllipse(150,150,100,100,pen, brush);
view = new QGraphicsView(scene,this);
setCentralWidget(view);
}
MainWindow::~MainWindow()
{
delete view;
delete scene;
}
view and scene are privete members of class MainWindow.
Program just shows white screen but there is no ellipse there.
any suggestions what am I doing wrong? Thanks in advance!
Upvotes: 2
Views: 1366
Reputation: 1997
I think that you problem is scene->setSceneRect(600,480,600,480);
.
Your ellipse is created outside of the view.
Upvotes: 4