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. Printing QTextTable And QPainter
Forum Updated to NodeBB v4.3 + New Features

Printing QTextTable And QPainter

Scheduled Pinned Locked Moved General and Desktop
qprintqpainterprintprintingqt5.4
1 Posts 1 Posters 1.5k Views 2 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.
  • R Offline
    R Offline
    root0x
    wrote on 16 Mar 2015, 17:14 last edited by root0x
    #1

    I am trying to print an invoice and i have found the best way is to use a QTextTable and for the text part of the invoice i am going to use QPainter but when i imploment this the only thing that shows is the table, i know the code for the painter is correct because when i comment the table code out the text shows fine. How can i show a texttable and text from Qpainter on the same printed page. My code is below.

    QPrinter Print(QPrinter::HighResolution);
    Print.setPaperSize(QPrinter::A4);
    Print.setOrientation(QPrinter::Landscape);
    Print.setDuplex(QPrinter::DuplexAuto);
    Print.setOrientation(QPrinter::Portrait);
    Print.newPage();
    QPrintDialog Printdialog(&Print);
    Printdialog.setWindowTitle("Print");
    Printdialog.exec();
    QPainter painter;
    painter.begin(&Print);
    QRect rect(0,0,250,250);
    painter.drawText(100, 100, "Test");
    QTextCursor cursor(ui->textBrowser->textCursor());
    cursor.movePosition(QTextCursor::Start);
    QTextTable *table = cursor.insertTable(ui->tableWidget_Invoice->rowCount() +1, 5);
    table->cellAt(0,0).firstCursorPosition().insertText("Product Code");
    table->cellAt(0,1).firstCursorPosition().insertText("Product Description");
    table->cellAt(0,2).firstCursorPosition().insertText("Qty");
    table->cellAt(0,3).firstCursorPosition().insertText("Unit Price");
    table->cellAt(0,4).firstCursorPosition().insertText("Total Price");
    for(int x = 0; x<ui->tableWidget_Invoice->rowCount(); x++) //Insert Contents of Form Table Into Printout Table
    {
    	table->cellAt(x+1,0).firstCursorPosition().insertText(ui->tableWidget_Invoice->item(x,2)->text());
    	table->cellAt(x+1,1).firstCursorPosition().insertText(ui->tableWidget_Invoice->item(x,1)->text());
    	table->cellAt(x+1,2).firstCursorPosition().insertText(ui->tableWidget_Invoice->item(x,0)->text());
    	table->cellAt(x+1,3).firstCursorPosition().insertText(ui->tableWidget_Invoice->item(x,3)->text());
    	table->cellAt(x+1,4).firstCursorPosition().insertText(ui->tableWidget_Invoice->item(x,4)->text());
    
    }
    ui->textBrowser->print(&Print);
    
    1 Reply Last reply
    0

    1/1

    16 Mar 2015, 17:14

    • Login

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