Qt6.24 QPrintPreViewDialog issues
Solved
Qt 6
-
hi ,
i used IED Qt6.24 to design a function that display file preview with QPrintPreViewDialog widget,it previewed nothing,it's so weirod,codes showed below:
void MainWindow::on_ActionPrintView_Clicked(void)
{
QPrinter printer;printer.setPageSize(QPageSize::A4); printer.setFullPage(true); //printer.setOutputFormat(QPrinter::NativeFormat); printer.setPageOrientation(QPageLayout::Portrait); //QMarginsF pageMargins(20,20,20,20); //printer.setPageMargins(pageMargins,QPageLayout::Millimeter); QPrintPreviewDialog preview(&printer,this,Qt::Window); preview.showNormal(); connect(&preview,&QPrintPreviewDialog::paintRequested,this,&MainWindow::previewPaint); preview.exec();
}
void MainWindow::previewPaint(QPrinter *printer)
{qDebug()<<"you clicked preview button!"; //QPainter p(printer); //p.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing|QPainter::SmoothPixmapTransform,true); //printer->newPage(); QCPDocumentObject *plotObjectHandler=new QCPDocumentObject(this); QTextCursor cursor; QTextDocument doc; doc.documentLayout()->registerHandler(QCPDocumentObject::PlotTextFormat,plotObjectHandler); cursor.insertText(QString(QChar::ObjectReplacementCharacter), QCPDocumentObject::generatePlotFormat(ui->plot, ui->plot->width(), ui->plot->height())); doc.print(printer); //p.drawText(20,20,"textdoc.toPlainText()");
}