PDA

View Full Version : qgraphicsview as mainwindow



Ashwin
14th June 2011, 18:40
Window::Window(QWidget *parent): KMainWindow(parent)
{
view=new QGraphicsView(this);
QGraphicsScene scene(0,0,1366,768);
scene.addText("Hello, world!");
view->setScene(&scene);
view->show();
}

i created above as my mainwindow .
"hello world " is not displaying on the window

helloworld
14th June 2011, 19:04
The QGraphicsScene is destroyed when falling out of scope if you create it on the stack.

Not sure about KMainWindow, but in a normal QMainWindow subclass you could do something like:



MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QGraphicsView *view = new QGraphicsView;
QGraphicsScene *scene = new QGraphicsScene(0, 0, 1366, 768, this);
scene->addText("Hello, world!");
view->setScene(scene);
setCentralWidget(view);
}

Ashwin
14th June 2011, 19:22
QGraphicsView *view=new QGraphicsView(this);
QGraphicsScene *scene=new QGraphicsScene(0, 0, 1366, 768);

worked:)