SHARE
TWEET

Untitled

a guest May 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  QTextDocument *doc = new QTextDocument;
  2. doc->setDocumentMargin(10);
  3. QTextCursor cursor(doc);
  4.  
  5. cursor.movePosition(QTextCursor::Start);
  6.  
  7. QTextTable *table = cursor.insertTable(properties.size() + 1, 2, tableFormat);
  8. QTextTableCell headerCell = table->cellAt(0, 0);
  9. QTextCursor headerCellCursor = headerCell.firstCursorPosition();
  10. headerCellCursor.insertText(QObject::tr("Name"), boldFormat);
  11. headerCell = table->cellAt(0, 1);
  12. headerCellCursor = headerCell.firstCursorPosition();
  13. headerCellCursor.insertText(QObject::tr("Value"), boldFormat);
  14.  
  15. for(int i = 0; i < properties.size(); i++){
  16.     QTextCharFormat cellFormat = i % 2 == 0 ? textFormat : alternateCellFormat;
  17.     QTextTableCell cell = table->cellAt(i + 1, 0);
  18.     cell.setFormat(cellFormat);
  19.     QTextCursor cellCursor = cell.firstCursorPosition();
  20.     cellCursor.insertText(properties.at(i)->name());
  21.  
  22.     cell = table->cellAt(i + 1, 1);
  23.     cell.setFormat(cellFormat);
  24.     cellCursor = cell.firstCursorPosition();
  25.     cellCursor.insertText(properties.at(i)->value().toString() + " " + properties.at(i)->unit());
  26. }
  27.  
  28. cursor.movePosition(QTextCursor::End);
  29. cursor.insertBlock();
  30.  
  31. //Print to PDF
  32. QPrinter printer(QPrinter::HighResolution);
  33. printer.setOutputFormat(QPrinter::PdfFormat);
  34. printer.setOutputFileName(filename);
  35. doc->print(&printer);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top