Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem when exporting graphic to file after calling fitInView()
Forum Updated to NodeBB v4.3 + New Features

Problem when exporting graphic to file after calling fitInView()

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srenzi
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved