Results 1 to 4 of 4

Thread: Putting a QGraphicsScene into QMdiSubWindow

  1. #1
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Putting a QGraphicsScene into QMdiSubWindow

    Hi,

    I have a MDI application. I have created a QGraphicsScene / QGraphicsView. I was wondering how I could put this into my QMdiSubWindow. I did do the following, but this doesn't seem correct as the scenes background isn't blue and the paint event is not being called on the graphics item?

    Qt Code:
    1. CanScene canScene;
    2. QGraphicsView view(&canScene);
    3.  
    4. QMdiSubWindow* subWindow = m_pworkspace->addSubWindow( &view );
    5. subWindow->setWindowIcon(QIcon(QString::fromUtf8(":/QTCanMonitor/Resources/Winamp.png")));
    6. subWindow->setMinimumSize( 200, 200 );
    7.  
    8. canScene.setBackgroundBrush(Qt::blue);
    9. view.resize(500,500);
    10. view.scale(0.95,0.95);
    11. view.show();
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Steve

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Putting a QGraphicsScene into QMdiSubWindow

    Create the scene on the heap. In your code, the scene gets deleted as soon as the function exists.

  3. #3
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Putting a QGraphicsScene into QMdiSubWindow

    Thanks.

    Ok, tried that, this is what I now have :

    Qt Code:
    1. CanScene* pcanScene = new CanScene(this);
    2. pcanScene->setSceneRect( QRectF( 0, 0, 5000, 5000 ) );
    3. pcanScene->setBackgroundBrush(Qt::blue);
    4. QGraphicsView view(pcanScene);
    5.  
    6. QMdiSubWindow* subWindow = m_pworkspace->addSubWindow( &view );
    To copy to clipboard, switch view to plain text mode 

    Still not blue background and paint event not being called?

    Regards,
    Steve

  4. #4
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Putting a QGraphicsScene into QMdiSubWindow

    Ok, it was a problem with not creating the graphics view on the heap also

    Marcel - many thanks for taking time to help, it is appreciated.

    Regards,
    Steve
    Last edited by steg90; 2nd October 2007 at 10:12.

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
  •  
Qt is a trademark of The Qt Company.