Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qtextbrowser and using rendering
Qt 6.11 is out! See what's new in the release blog

Qtextbrowser and using rendering

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    hello
    im an entry level programmer and new to QT also so im still getting my way around this stuff. I have a program where i am trying to print a pdf and in this pdf i wanna show a table and image graph or render a graph to be exact. so far i get my text table but my image wont show and it only shows one page. So far i have tried QpaintEditor and QImagetext, being i might have not set them up properly so and help would be amazing.

    so this is how i set up my pdf and how i set up the table that works you can see my attempt to use QImageText

    @void MainWindow::QTableWidget2QTextBrowser(QTableWidget *tabW,QTextBrowser *editor)
    {
    ///creates writing format
    QTextCharFormat NormalFormat;
    editor->setCurrentCharFormat(NormalFormat);

    //create pointer to current cursor location
    QTextCursor cursor =editor->textCursor();
    cursor.beginEditBlock();
    
    QTextTableFormat tableFormat;
    tableFormat.setAlignment(Qt::AlignLeft);
    tableFormat.setBackground(QColor("#ffffff"));
    tableFormat.setCellPadding(3);
    tableFormat.setCellSpacing(3);
    
    QTextTable *tab=cursor.insertTable(tabW->rowCount()+1,tabW->columnCount(),tableFormat);
    QTextFrame *frame=cursor.currentFrame();
    QTextFrameFormat frameFormat=frame->frameFormat();
    frameFormat.setBorder(0);
    frame->setFrameFormat(frameFormat);
    
    QTextCharFormat format_entete_tab;
    format_entete_tab.setFontPointSize(12);
    format_entete_tab.setFontWeight(QFont::Bold);
    
    QTextCharFormat format_cellule;
    format_cellule.setFontPointSize(11);
    
    for(int i=0;i<tabW->columnCount();i++)
    {
        QTextTableCell titre = tab->cellAt(0,i);
        QTextCursor cellCursor=titre.firstCursorPosition();
        cellCursor.insertText(tabW->horizontalHeaderItem(i)->text(),format_entete_tab);
    }
    QTextTableCell cell;
    QTextCursor cellCursor;
    for(int row=1;row<tab->rows();row++)
    {
        for(int col=0;col<tab->columns();col++)
        {
            cell=tab->cellAt(row,col);
            cellCursor=cell.firstCursorPosition();
            cellCursor.insertText(tr("%1").arg(tabW->item(row-1,col)->text()),format_cellule);
        }
    }
    cursor.endEditBlock();
    

    }@

    This is the problem
    @// // Print Graph

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

    and this is how i set up my my QtextBrowser if there is an error here to in my setup please say so i need to learn.
    @void MainWindow::QTableWidget2QTextBrowser(QTableWidget *tabW,QTextBrowser *editor)
    {
    ///creates writing format
    QTextCharFormat NormalFormat;
    editor->setCurrentCharFormat(NormalFormat);

    //create pointer to current cursor location
    QTextCursor cursor =editor->textCursor();
    cursor.beginEditBlock();
    
    QTextTableFormat tableFormat;
    tableFormat.setAlignment(Qt::AlignLeft);
    tableFormat.setBackground(QColor("#ffffff"));
    tableFormat.setCellPadding(3);
    tableFormat.setCellSpacing(3);
    
    QTextTable *tab=cursor.insertTable(tabW->rowCount()+1,tabW->columnCount(),tableFormat);
    QTextFrame *frame=cursor.currentFrame();
    QTextFrameFormat frameFormat=frame->frameFormat();
    frameFormat.setBorder(0);
    frame->setFrameFormat(frameFormat);
    
    QTextCharFormat format_entete_tab;
    format_entete_tab.setFontPointSize(12);
    format_entete_tab.setFontWeight(QFont::Bold);
    
    QTextCharFormat format_cellule;
    format_cellule.setFontPointSize(11);
    
    for(int i=0;i<tabW->columnCount();i++)
    {
        QTextTableCell titre = tab->cellAt(0,i);
        QTextCursor cellCursor=titre.firstCursorPosition();
        cellCursor.insertText(tabW->horizontalHeaderItem(i)->text(),format_entete_tab);
    }
    QTextTableCell cell;
    QTextCursor cellCursor;
    for(int row=1;row<tab->rows();row++)
    {
        for(int col=0;col<tab->columns();col++)
        {
            cell=tab->cellAt(row,col);
            cellCursor=cell.firstCursorPosition();
            cellCursor.insertText(tr("%1").arg(tabW->item(row-1,col)->text()),format_cellule);
        }
    }
    cursor.endEditBlock();
    

    }@

    1 Reply Last reply
    0

    • Login

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