Results 1 to 3 of 3

Thread: qgraphicsview as mainwindow

  1. #1
    Join Date
    Jun 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qgraphicsview as mainwindow

    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

  2. #2
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: qgraphicsview as mainwindow

    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:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. QGraphicsScene *scene = new QGraphicsScene(0, 0, 1366, 768, this);
    5. scene->addText("Hello, world!");
    6. view->setScene(scene);
    7. setCentralWidget(view);
    8. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qgraphicsview as mainwindow

    QGraphicsView *view=new QGraphicsView(this);
    QGraphicsScene *scene=new QGraphicsScene(0, 0, 1366, 768);

    worked

Similar Threads

  1. QGraphicsView transparent over another QGraphicsView
    By evergreen in forum Qt Programming
    Replies: 0
    Last Post: 30th May 2011, 10:22
  2. Replies: 1
    Last Post: 12th April 2011, 09:53
  3. QGraphicsView + MainWindow
    By lioncub in forum Newbie
    Replies: 3
    Last Post: 26th February 2011, 10:31
  4. Replies: 1
    Last Post: 6th July 2010, 12:03
  5. MainWindow
    By amagdy.ibrahim in forum Newbie
    Replies: 6
    Last Post: 14th June 2008, 14:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.