简体   繁体   English

QPrintDialog在Windows中显示两次

[英]QPrintDialog is shown twice in windows

I've written this piece of code which takes the contents of a QPlainTextEditor and then sends that to a QPrint object it the the user accepts QPrintDialog 我已经编写了这段代码,它接受了QPlainTextEditor的内容,然后将其发送给用户接受QPrintDialog的QPrint对象。

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();
    }
}

it works OK under KDE (didn't try that under Gnome), but in Windows, whenever I accepts the printDialog, the dialog will be shown again and if I accept that again, it will send the text to the printer. 它在KDE下可以正常工作(在Gnome中没有尝试过),但是在Windows中,每当我接受printDialog时,对话框都会再次显示,如果再次接受,它将文本发送给打印机。

how can I fix that? 我该如何解决?

I think it's enough to call only exec() . 我认为只调用exec()就足够了。 You can remove the call of show() . 您可以删除对show()的调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM