[Qt-interest] Using OpenGL to render and transform a SVG in a QDialog

Sven Grunewaldt strayer at olle-orks.org
Mon Oct 18 22:08:57 CEST 2010


Thanks for your reply Max,

rotating before rendering did indeed work:
void SvgGLWidget::paintEvent(QPaintEvent *)
{
	QPainter painter;
	QTransform trans;
	trans.rotate(25);
	painter.begin(this);
	painter.setTransform(trans);
	renderer->render(&painter);
	painter.end();
}

(I think the begin() and end() functions are not needed if I construct
the painter with (this), but I was playing around with the QPainter and
just left it that way.)

The image does rotate now but it keeps the top left corner of the SVG in
the top left corner of the QGLWidget:
http://dl.dropbox.com/u/256059/tmp/qglwidget.png

I guess it is my responsibility to recalculate the position and "center"
the SVG again... I can't see how I'm supposed to do that with QTransform
or QPainter other than moving the ViewPort - is this correct?

Regards,
Sven Grunewaldt

Am 18.10.2010 22:00, schrieb Max Waterman:
> Did you try rotating before rendering?
> 
> Max.
> 
> ----- Original message -----
>> Hi,
>>
>> I need to show a SVG graphic which resembles a compass needle. This
>> graphic will be rotated several times per second, so to keep this at
>> least a little bit with good performance I thought about using a
>> QGLWidget since OpenGL should be able to render a vector graphic pretty
>> easily.
>>
>> The QtSvg documentation states:
>> Using QSvgRenderer, Scalable Vector Graphics (SVG) can be rendered onto
>> any QPaintDevice subclass, including QWidget, QImage, and QGLWidget.
>>
>> I tried to implement this with a simple class which extends QGLWidget
>> and reimplements the paintEvent:
>> SvgGLWidget::SvgGLWidget(QString svgFile, QWidget *parent) :
>>     QGLWidget(parent)
>> {
>>     renderer = new QSvgRenderer(svgFile, this);
>> }
>>
>> void SvgGLWidget::paintEvent(QPaintEvent *event)
>> {
>>     QPainter painter(this);
>>     renderer->render(&painter);
>>     painter.rotate(100);
>> }
>>
>> The SVG is indeed rendered correctly, but the rotate(100) does not work
>> at all. I guess I'm just missing something here or just do it the wrong
>> way(TM).
>>
>> Is this the correct way to render a SVG which will be rotated several
>> times per second? Why does the rotate() method not work?
>>
>> Regards,
>> Sven Grunewaldt
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 



More information about the Qt-interest-old mailing list