C++ (Qt)void QwtGraphic::setDefaultSize( const QSizeF &size ){const double w = qMax( 0.0, double( size.width() ) );const double h = qMax( 0.0, double( size.height() ) ); // или такconst qreal w = qMax( qreal( 0.0 ), size.width() );const qreal h = qMax( qreal( 0.0 ), size.height() ); d_data->defaultSize = QSizeF( w, h );}
#include "canvas.h"#include <qwt_graphic.h>#include </Code/qtsvg-opensource-src-5.0.0/include/QtSvg/qsvgrenderer.h>Canvas::Canvas( Mode mode, QWidget *parent ): QWidget( parent ), d_mode( mode ){ const int m = 10; setContentsMargins( m, m, m, m ); if ( d_mode == Svg ) d_renderer = new QSvgRenderer( this ); else d_graphic = new QwtGraphic();}Canvas::~Canvas(){ if ( d_mode == VectorGraphic ) delete d_graphic;}void Canvas::setSvg( const QByteArray &data ){ if ( d_mode == VectorGraphic ) { d_graphic->reset(); QSvgRenderer renderer; renderer.load( data ); QPainter p( d_graphic ); renderer.render( &p, renderer.viewBoxF() ); p.end(); } else { d_renderer->load( data ); } update();}void Canvas::paintEvent( QPaintEvent * ){ QPainter painter( this ); painter.save(); painter.setPen( Qt::black ); painter.setBrush( Qt::white ); painter.drawRect( contentsRect().adjusted( 0, 0, -1, -1 ) ); painter.restore(); painter.setPen( Qt::NoPen ); painter.setBrush( Qt::NoBrush ); render( &painter, contentsRect() );}void Canvas::render( QPainter *painter, const QRect &rect ) const{ if ( d_mode == Svg ) { d_renderer->render( painter, rect ); } else { d_graphic->render( painter, rect ); }}
...#include </Code/qtsvg-opensource-src-5.0.0/include/QtSvg/qsvgrenderer.h>...
LIBS += -L/Code/qtsvg-opensource-src-5.0.0/lib -lQt5Svg