简体   繁体   English

单击“打印”按钮后,重新出现“ Qt打印”对话框

[英]Qt Print Dialog reappears after Print button clicked

I am trying to print a graphic in Qt. 我正在尝试在Qt中打印图形。

The signals and slots are connected as follows : 信号和插槽的连接方式如下:

connectStat = connect(_ui->printButton, SIGNAL(clicked()), this, SLOT(doPrint()));

and the slot is as follows: 插槽如下:

...
QGraphicsScene * m_scene;
...
void GraphDrawerWidget::doPrint() {
    QPrinter printer;
    if (QPrintDialog(&printer).exec() == QDialog::Accepted) {
         printer.setOrientation(QPrinter::Landscape);
       QPainter painter(&printer);
        painter.setRenderHint(QPainter::Antialiasing);
        m_scene->render(&painter);
    }
}

The Print dialog does appear, and I can get the scene to print by clicking on the Print button. 确实会出现“打印”对话框,并且单击“打印”按钮可以使场景打印。 However, after I do this, the print dialog is showed again. 但是,执行此操作后,将再次显示打印对话框。 It doesn't matter if I click Print, Cancel or the Window X button, it still shows after the click. 单击“打印”,“取消”或“ X窗口”按钮都没关系,单击后它仍然显示。

Am I possibly connecting the signals/slots wrong? 我可能将信号/插槽连接错了吗?

Found it! 找到了! It seems I was doing the connect() in another method called run() (GraphDrawerWidget::run()) which is where I was feeding the data into the Graphic. 看来我正在使用另一种称为run()(GraphDrawerWidget :: run())的方法进行connect(),这是我将数据馈入图形的地方。

This run() got called once for each signal I was adding to the graphic, so the same slot was connected multiple times. 对于我添加到图形中的每个信号,该run()都会被调用一次,因此同一插槽被连接了多次。

I am now connecting in the constructor and everything works fine. 我现在正在连接构造函数,一切正常。

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

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