Hi,
I have a QGraphicsView linked to a node graph, all works fine but one problem is there : the resize.
The resize works good but when you resize, the QGraphicsView is not centered anymore.
The behavior needed is to have the same view but with more space around.
Is it possible to have that ? How can it be achieved ?
Thanks for the help
EDIT :
Here one solution I have found if someone has the same problem, reimplement the resizeEvent of QGraphicsView :
{
// Base class.
// Get the old size.
const QSize OldSize
= event
->oldSize
();
// Map to scene.
const QPointF CenterPos
= mapToScene
( OldSize.
width() / 2, OldSize.
height() / 2 );
// Center on the center pos.
centerOn( CenterPos );
}
void CEditorNodeView::resizeEvent( QResizeEvent* event )
{
// Base class.
QGraphicsView::resizeEvent( event );
// Get the old size.
const QSize OldSize = event->oldSize();
// Map to scene.
const QPointF CenterPos = mapToScene( OldSize.width() / 2, OldSize.height() / 2 );
// Center on the center pos.
centerOn( CenterPos );
}
To copy to clipboard, switch view to plain text mode
Bookmarks