#include "MyGraphicsView.h"MyGraphicsView::MyGraphicsView( QWidget * parent ) :QGraphicsView( parent ){ setSceneRect( 0, 0, 500, 500 ); backgroundImage = 0; setViewportUpdateMode( QGraphicsView::FullViewportUpdate );}void MyGraphicsView::drawBackground( QPainter * painter, const QRectF & rect ){ if ( backgroundImage == 0 ) { QGraphicsView::drawBackground( painter, rect ); } else { painter->save(); painter->drawImage( 0, 0, *backgroundImage ); painter->restore(); }}void MyGraphicsView::slotSetBackground(){ //TODO_1: add QFIleDialog backgroundImage = new QImage; backgroundImage->load( "Resources/background.png" ); backgroundImage->scaled( sceneRect().width(), sceneRect().height() );}
C++ (Qt)QGraphicsView::viewport()->update();
painter->drawImage( rect, *backgroundImage )
void MyGraphicsView::drawBackground( QPainter * painter, const QRectF & rect ){ if ( backgroundImage == 0 ) { QGraphicsView::drawBackground( painter, rect ); } else { painter->save(); painter->drawImage( rect, *backgroundImage ); painter->restore(); QGraphicsView::viewport()->update(); }}