C++ (Qt) QList <QSvgWidget*> ground;for ( int i = 0; i < 5; i++ ) { ground.append( new QSvgWidget( this ) ); ground.back()->resize( x, x ); ground.back()->setGeometry( xX, x, x, x ); ground.back()->load( QString( ":/spheres.svg" ) ); ground.back()->show(); xX += x; }
C++ (Qt) for ( int i = 0; i < 5; i++ ) ground[i]->hide();
C++ (Qt)QSvgRenderer::render ( QPainter * painter, const QRectF & bounds )
C++ (Qt)class SvgNativeView : public QWidget{ Q_OBJECT public: SvgNativeView(const QString &file, QWidget *parent=0); virtual QSize sizeHint() const;protected: virtual void paintEvent(QPaintEvent *event); virtual void wheelEvent(QWheelEvent *event); private: QSvgRenderer *doc;};
C++ (Qt)SvgNativeView::SvgNativeView(const QString &file, QWidget *parent) : QWidget(parent){ doc = new QSvgRenderer(file, this); connect(doc, SIGNAL(repaintNeeded()), this, SLOT(update()));} void SvgNativeView::paintEvent(QPaintEvent *){ QPainter p(this); p.setViewport(0, 0, width(), height()); doc->render(&p);} QSize SvgNativeView::sizeHint() const{ if (doc) return doc->defaultSize(); return QWidget::sizeHint();} void SvgNativeView::wheelEvent(QWheelEvent *e){ const double diff = 0.1; QSize size = doc->defaultSize(); int width = size.width(); int height = size.height(); if (e->delta() > 0) { width = int(this->width()+this->width()*diff); height = int(this->height()+this->height()*diff); } else { width = int(this->width()-this->width()*diff); height = int(this->height()-this->height()*diff); } resize(width, height);}
C++ (Qt)void NewWidget::paintEvent ( QPaintEvent * e ){ QSvgWidget::paintEvent(e); //рисуется содержимое QSvgWidget'а //дальше рисуешь свое.}
C++ (Qt)void Field::paintEvent( QPaintEvent *event ){ QSvgWidget::paintEvent( event ); QPainter painter( this ); painter.setRenderHint( QPainter::Antialiasing ); painter.drawLine( 0, 0, 500, 500 );}
C++ (Qt)void Field::paintEvent( QPaintEvent *event ){ svgL->paintEvent( event ); QPainter painter( this ); painter.setRenderHint( QPainter::Antialiasing ); painter.drawLine( 0, 0, 500, 500 );}
C++ (Qt)#ifndef MYSVGWIDGET_H#define MYSVGWIDGET_H #include <QSvgWidget> class MySvgWidget : public QSvgWidget{ Q_OBJECT;public:// MySvgWidget( QWidget *parent=0 ); }; #endif
C++ (Qt)#include "mysvgwidget.h" //MySvgWidget::MySvgWidget( QWidget *parent )//{//}