我编写了这段代码,它接受了QPlainTextEditor的内容,然后将其发送到QPrint对象,用户接受了QPrintDialog
void MainWindow::on_actionPrint_triggered()
{
printPage = new QPrinter(QPrinter::HighResolution);
QPrintDialog *printDialog = new QPrintDialog(printPage,this);
printDialog->show();
if(printDialog->exec() == QPrintDialog::Accepted){
QPainter *painterToPrnt = new QPainter;
painterToPrnt->begin(printPage);
painterToPrnt->drawText(printPage->pageRect(),ui->plainTextEdit->toPlainText());
painterToPrnt->end();
}
}
它在KDE下工作正常(没有尝试在Gnome下),但在Windows中,每当我接受printDialog时,对话框将再次显示,如果我再次接受,它会将文本发送到打印机。
我该如何解决?
答案 0 :(得分:4)
我认为只调用exec()
就足够了。您可以移除show()
。