May 2, 2011

Peppy Peppy
Hobby Entomologist
389 posts

[Solved]GraphicsWidget & GraphicsScene - auto resizing

 

Is any way to autoresize GraphicsWidget by resizeEvent of main window there??

1 reply

May 2, 2011

ZapB ZapB
Robot Herder
1356 posts

Yes. Basically you do this:

  • Derive a class from QGraphicsView, MyGraphicsView, say.
  • Use this instead of QGraphicsView in your application. Remember to add this to a layout in your application widget hierarchy so that the MyGraphicsView gets resize events as the mainwindow is resized.
  • Override the resizeEvent( QResizeEvent* ) function in your MyGraphicsView class and do something like this:

  1. void MyGraphicsView::resizeEvent( QResizeEvent* e )
  2. {
  3.     double w = ( e->size().width() - 20.0 );
  4.     double h = ( e->size().height() - 20.0 );
  5.     m_myGraphicsWidget->resize( w, h );
  6. }

You may also want to update the QGraphicsScene’s sceneRect in that function too so that it closely bounds the resulting scene. It depends on your item/widget hierarchy what you want to do though.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

 
  ‹‹ Infinite loop and signal deluge      Display webpage using the source code from a QByteArray ››

You must log in to post a reply. Not a member yet? Register here!