[Qt-interest] Using OpenGL to render and transform a SVG in a QDialog
Sven Grunewaldt
strayer at olle-orks.org
Thu Oct 28 01:14:54 CEST 2010
Hi Andre,
thanks a lot for your response. (It looks like it's always you pointing
me into the correct direction... so many many thanks for helping me
again and again ;) )
My final implementation:
void SvgGLWidget::setRotation(int rotation)
{
_rotation = rotation;
update();
}
void SvgGLWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.translate(width()/2, height()/2);
painter.rotate(_rotation);
painter.translate(-(width()/2), -(height()/2));
renderer->render(&painter, painter.viewport());
}
And it works like a charm! Now I only need to fix the aspect ratio and
find out why the "Arial" font in the SVG does only work on Windows XP...
but I hope I'll figure that out myself.
Regards,
Sven Grunewaldt
Am 19.10.2010 08:16, schrieb Andre Somers:
> Op 18-10-2010 22:08, Sven Grunewaldt schreef:
>> Thanks for your reply Max,
>>
>> rotating before rendering did indeed work:
> (...)
>> 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?
> Yes. And it is not that hard. The easiest way is to do it in a few
> steps: first, create a transformation that represents the translation.
> You just make sure that you translate the centre of your needle to the
> origin of your painter. Create the inverted transformation too, so you
> can translate back. Then, create your total matrix by multiplying the
> transformation matrices: TM = translate center to origin * rotation *
> translate back. This matrix should do what you want.
>
> André
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list