QPrinter printer(QPrinter::HighResolution); QPrintDialog printDialog(&printer, this); if (printDialog.exec() == QDialog::Accepted) { QPainter painter(&printer); QPixmap image; image = image.grabWidget(ui->centralWidget,0,0,ui->centralWidget->width(), ui->centralWidget->height()); QRect rect = painter.viewport(); QSize size = image.size(); size.scale(rect.size(), Qt::KeepAspectRatio); //此处保证图片显示完整 painter.setViewport(rect.x(), rect.y(),size.width(), size.height()); painter.setWindow(image.rect()); painter.drawPixmap(0,0,image); }
阅读(3357) | 评论(0) | 转发(0) |