Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved]GraphicsWidget & GraphicsScene - auto resizing
Peppy last edited by
Is any way to autoresize GraphicsWidget by resizeEvent of main window there??
ZapB last edited by
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:
void MyGraphicsView::resizeEvent( QResizeEvent* e )
double w = ( e->size().width() - 20.0 );
double h = ( e->size().height() - 20.0 );
m_myGraphicsWidget->resize( w, h );
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.