In QPrintPreviewDialog slot is not being called by the signal--- paintRequested(QPrinter *printer)



  • Hi,
    In the constructor I have written like this,

    m_Printer=new QPrinter;
        m_Preview=new QPrintPreviewDialog(m_Printer);
        connect(m_Preview,SIGNAL(paintRequested(QPrinter*)),this,SLOT(PrintPreviewSlot(QPrinter *)));
    

    In the SLOT........

    void Printer::PrintPreviewSlot(QPrinter *printer)
    { qDebug()<<Q_FUNC_INFO;
    }
    

    In some other function i am setting parameters of the QPrinter obj like this,

    {
        m_Printer->setOutputFileName("Reciepts");
        m_Printer->setFullPage(false);
        m_Printer->setPageOrientation(QPageLayout::Landscape);
        m_Printer->setPaperSize(QPrinter::A5);
        QPrintDialog printDialog(m_Printer);
      if (printDialog.exec() == QDialog::Accepted) {
    painter=new QPainter;
        painter->begin(m_Printer);
    some text-------
        painter->end();
    }
    m_Preview->exec();  //obj of print preview within this function
    }// end of func
    

    I am getting blank preview why ???
    With Thanks
    Phadnis


  • Qt Champions 2016



  • Hi mrjj,
    qDebug()<<connect(m_Preview,SIGNAL(paintRequested(QPrinter*)),this,SLOT(PrintPreviewSlot(QPrinter *)));
    is true
    With Thanks,
    Phadnis


  • Qt Champions 2016

    @Phadnis
    Ok. super.
    Then my guess is you do something unexpected with the painter. :)

    This works

    void MainWindow::on_pushButton_clicked()
    {
        QPrinter printer(QPrinter::HighResolution);
        QPrintPreviewDialog preview(&printer, this);
        preview.setWindowFlags ( Qt::Window );
        connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
        preview.exec();
    
    
    }
    
    void MainWindow::printPreview(QPrinter *printer) {
    
        QPainter p(printer);
        p.drawText(500,500,"U WIN");
    
    }
    

    alt text


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.