简体   繁体   中英

Qt Print Dialog reappears after Print button clicked

I am trying to print a graphic in 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.

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.

This run() got called once for each signal I was adding to the graphic, so the same slot was connected multiple times.

I am now connecting in the constructor and everything works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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