In my MainWindow I use this:
QRect rect
=this
->widget
->view
->viewport
()->rect
();
this
->scene
->setSceneRect
(QRectF(0,
0,rect.
width(),rect.
height()));
QRect rect=this->widget->view->viewport()->rect();
this->scene->setSceneRect(QRectF(0,0,rect.width(),rect.height()));
To copy to clipboard, switch view to plain text mode
Perhaps you should also look into the ->mapTo... and ->mapFrom... methods.
To know when the scene's size is being changed by the user I subclass the CentralWidget and plug myself into the resizeEvent, triggering a signal from there:
CentralWidget
::CentralWidget(QWidget *parent
) :{
}
{
emit this->centralWidgetWasResized();
}
bool CentralWidget
::event(QEvent * event
) {
if (event
->type
()==QEvent::Show) emit this
->centralWidgetWasResized
();
event->ignore();
}
CentralWidget::CentralWidget(QWidget *parent) :
QWidget(parent)
{
}
void CentralWidget::resizeEvent(QResizeEvent *)
{
emit this->centralWidgetWasResized();
}
bool CentralWidget::event(QEvent * event)
{
if (event->type()==QEvent::Show) emit this->centralWidgetWasResized();
event->ignore();
return QWidget::event(event);
}
To copy to clipboard, switch view to plain text mode
Actually I am not quite sure if this tackles your problem in the right way, but it might give you some ideas.
Bookmarks