[Interest] QtSVG deprecated
Chris Meyer
cmeyer1969+qt at gmail.com
Tue Jan 10 18:42:05 CET 2012
On Tue, Jan 10, 2012 at 5:13 AM, Martin Holmes <mholmes at uvic.ca> wrote:
> This all seems very disappointing to me. How would you actually use
> webkit to provide SVG support to QImage?
I extracted this code from my source to convert SVG to QImage using
QtWebKit. It's untested in this specific form, but should give you the
idea.
And, again, if you want any chance of being accepted on the Mac App
Store, you can't include QtWebKit (at least in its current form, which
uses a library that Apple provides that uses private API calls).
#include <QGraphicsWebView>
QImage makeSvgImage(const QSize &svg_size,
const QByteArray &svg_byte_array,
const QString &svg_mime_type)
{
QImage image(svg_size);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::TextAntialiasing);
QRect frame(QPoint(), image.size());
std::auto_ptr<QGraphicsScene> scene(new QGraphicsScene(frame));
QGraphicsWebView *web_view = new QGraphicsWebView();
web_view->setGeometry(frame);
web_view->setContent(svg_byte_array, svg_mime_type);
web_view->setOpacity(0.001); // work around bug in web view 4.8
(draws white background without this)
scene->addItem(web_view);
scene->render(&painter);
return image;
}
More information about the Interest
mailing list