qt - Printing QGraphicsScene cuts objects in half -
i want print what's on qgraphicsscene:
void mainwindow::on_print_clicked() { if (template_ptr != q_nullptr) { qprinter printer(qprinter::highresolution); if (qprintdialog(&printer, this).exec() == qdialog::accepted) { if (qpagesetupdialog(&printer, this).exec() == qdialog::accepted) { qpainter painter(&printer); painter.setrenderhint(qpainter::antialiasing); painter.setrenderhint(qpainter::textantialiasing); qreal x, _y, h, w, fake; ui->graphicsview->scenerect().getrect(&x, &_y, &w, &fake); h = template_ptr->page_height*2.0; qint32 page = 0; while (true) { qreal y = _y + h*page; qrectf leftrect(x, y, w, template_ptr->page_height*2.0*template_ptr->max_pages - h*page); if (ui->graphicsview->scene()->items(leftrect).length() <= 0) { break; } qrectf sourcerect(x, y, w, h); ui->graphicsview->scene()->render(&painter, printer.pagerect(), sourcerect); printer.newpage(); page++; } } } } }
every point on lists single qgraphicsitem , don't know what's easiest way move items doesn't fit within page, next page... error-prone mathematics achieve i'm pretty sure can resolved in elegant way.
what do...
step 1: first create copy of scene (a new qgraphicsscene
same size original) , move items there.
step 2: create temporary scene each new page, scenerect
equal section wish print.
step 3: move items scene copy, contained
in scenerect
of temp scene.
step 4: after printing, move printed items original scene...
step 5: shorten copy scene bounding rect bounding rect of items still left inside it. (to allow step 4 place items in place, change x/y coordinates change w/h)
repeat steps 3 5 till copy scene empty.
Comments
Post a Comment