Results 1 to 2 of 2

Thread: MDI display Item in QGraphicsView

  1. #1
    Join Date
    Nov 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default MDI display Item in QGraphicsView

    Use Qt 4.3.2, I have a mainwindow and a button, to open a MDI subwindow to display some GraphicsItem in a scene in GraphicsView. I can open subwindow,but can't see anything.
    follow is my program. Does anyone know?
    //------- main.cpp --------------
    #include <QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    MainWindow mainWin;

    mainWin.show();
    return app.exec();
    }

    //------- mainwindow.h ----------
    #include <QMainWindow>

    class QMdiArea;

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow();
    private:
    QMdiArea *mdiArea;
    };
    #endif

    //-------- mainwindow.cpp -----------
    void MainWindow::disp()
    { //draw a sun Item in scene,and put scene into view
    QGraphicsEllipseItem *sun = new QGraphicsEllipseItem(0,0,50,50);
    sun->setBrush(Qt::red);
    sun->setPen(QPen(Qt::red));

    QGraphicsScene scene(0, 0, 60,60);
    scene.addItem(sun);

    QGraphicsView view(&scene);

    QMdiSubWindow *subWindow = mdiArea->addSubWindow(&view);

    subWindow->show();
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MDI display Item in QGraphicsView

    You create both the scene and the view on the stack, so they go out of scope when disp() returns.

Similar Threads

  1. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  2. QComboTableItem display the widest item
    By Equilibrium in forum Qt Programming
    Replies: 0
    Last Post: 3rd December 2007, 13:01
  3. QGraphicsView and item focus
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2007, 20:36
  4. how to display full tree item name on mouse move ?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 15th November 2006, 08:41
  5. Can't change the text display of a QTreeview item.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2006, 01:03

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.