Problem when exporting graphic to file after calling fitInView()
-
Hi, I'm writing an app which draws a graphic in a QGraphicsView and if the scene rect changes, it calls fitInView() in order to rescale the graph and make it easier to analyze. This is what I see on the screen:
!http://img40.imageshack.us/img40/7420/correcty.png(Correct image)!
I'm trying to add the option to export the graphic to a svg file, but this is what I get:
!http://img804.imageshack.us/img804/6935/incorrect.png(Incorrect image)!
This is the code I'm calling when the rect changes:
@void Mainview::_on_scene_rect_changed(QRectF rect)
{
_plotview->fitInView(rect); // _plotview is a QGraphicsView *
}
@And this is the function to export to SVG, which creates the incorrect image:
@void Mainview::on__file_export_to_svg_action_triggered()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save SVG"), "", tr("SVG files (*.svg)"));if (filename.isEmpty()) { return; } QSvgGenerator generator; generator.setFileName(filename); int width = _plotview->geometry().width(); int height = _plotview->geometry().height(); generator.setSize(QSize(width, height)); generator.setViewBox(QRect(0, 0, width, height)); QPainter painter; painter.begin(&generator); _plotview->render(&painter); painter.end();
}
@I've tried different things with the matrix and transformation of the view, but I didn't succeed in having the image I see on the screen to a file. If I call:
@ _plotview->fitInView(rect, Qt::KeepAspectRatio);
@the output I get in the file is the same as the one I see on the screen, but I don't intend to keep the aspect ratio of the graphic. What am I doing wrong? Any hint will be much appreciated. :-)
Thanks for reading!