Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In QPrintPreviewDialog slot is not being called by the signal--- paintRequested(QPrinter *printer)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 976 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Phadnis
    wrote on last edited by VRonin
    #1

    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

    mrjjM 1 Reply Last reply
    0
    • P Phadnis

      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

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Phadnis said in In QPrintPreviewDialog slot is not being called by the signal--- paintRequested(QPrinter *printer):

      connect

      Does it return true?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Phadnis
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • P Phadnis

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved