Error rendering with Qpainter



  • the program generates a pdf, in this pdf there is a QTextBrowser table and three graphs that are rendered using qPainter.

    @ int index=ui->m_tableWidgetLogger->currentRow();
    if(index<0)
    return;

    QPrinter *printer = new QPrinter(QPrinter::HighResolution);
    
    printer->setPaperSize(QPrinter::A4);
    printer->setOutputFormat(QPrinter::PdfFormat);
    printer->setOrientation(QPrinter::Portrait);
    printer->setFullPage(true);
    printer->setOutputFileName(fileName);
    QPainter p;
    

    // p->begin(printer);

        // Print Summary
    
           QTableWidget *summaryTab=new QTableWidget();
           m_mainApp->m_table->SetTableWidget(summaryTab);
           summaryTab->setGeometry(0,0,printer->pageRect().width(),printer->pageRect().height());
           summaryTab->setAutoScroll(true);
           m_mainApp->m_table->InitTableSummary(summaryTab);
           m_mainApp->m_table->FillTableSummary(summaryTab,index);
           summaryTab->setAlternatingRowColors(true);
           summaryTab->setFrameShape(QFrame::NoFrame);
           QTextBrowser *editor= new QTextBrowser;
           QTableWidget2QTextBrowser(summaryTab,editor);
           editor->print(printer);
    

    // QPainter painter;
    // painter.begin(printer);
    // painter.renderHints(QPainter::Antialiasing);
    // painter.renderHints(QPainter::RenderHint);

    if(m_mainApp->mLoggerList[index].recCurrentAddress)
    {
    
          // Print Graph
        p.begin(printer);
    

    // QWidget render;
    // render.paintingActive();
    QwtPlotRenderer renderer;
    renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
    renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
    renderer.render(m_plot,&p,QRect(0,printer->height()/2,printer->width(),printer->height()/2.2));
    printer->newPage();

        // Print Histogram
        renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
        renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
        renderer.render(m_histogram,&p,QRect(0,0,printer->width(),printer->height()/2.2));
        renderer.render(m_histogram,&p,QRect(0,printer->height()/2,printer->width(),printer->height()/2.2));
        // Print Table
    
        QTableWidget *table=new QTableWidget();
        m_mainApp->m_table->SetTableWidget(table);
        table->setGeometry(0,0,printer->pageRect().width(),printer->pageRect().height());
        table->setAutoScroll(false);
        m_mainApp->m_table->InitTablePrint(index,printer->pageRect().width());
        int nbPage=m_mainApp->m_table->GetNbPrintPage(index,printer->pageRect().height());
    
    
            for(int page=0;page<nbPage;page++)
               {
    
            m_mainApp->m_table->currentIndex=-1;
            m_mainApp->m_table->InitTablePrint(index,printer->pageRect().width());
            m_mainApp->m_table->FillTablePrint(index,printer->pageRect().height(),page);
            table->render(&p,QPoint(0,0),QRegion(0,0,printer->pageRect().width(),printer->pageRect().height(),QRegion::Rectangle),QWidget::DrawChildren);
           // table->widget->render(&painter,QPoint(0,0),QRegion(0,0,printer->pageRect().width(),printer->pageRect().height(),QRegion::Rectangle),QWidget::DrawChildren);
    
               }
            p.end();
        }@
    

    the issue is i get the render and the table disappears or the render disappears and table is shown. anyone have any ideas.




Log in to reply
 

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