Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QTextDocument *doc = new QTextDocument;
- doc->setDocumentMargin(10);
- QTextCursor cursor(doc);
- cursor.movePosition(QTextCursor::Start);
- QTextTable *table = cursor.insertTable(properties.size() + 1, 2, tableFormat);
- QTextTableCell headerCell = table->cellAt(0, 0);
- QTextCursor headerCellCursor = headerCell.firstCursorPosition();
- headerCellCursor.insertText(QObject::tr("Name"), boldFormat);
- headerCell = table->cellAt(0, 1);
- headerCellCursor = headerCell.firstCursorPosition();
- headerCellCursor.insertText(QObject::tr("Value"), boldFormat);
- for(int i = 0; i < properties.size(); i++){
- QTextCharFormat cellFormat = i % 2 == 0 ? textFormat : alternateCellFormat;
- QTextTableCell cell = table->cellAt(i + 1, 0);
- cell.setFormat(cellFormat);
- QTextCursor cellCursor = cell.firstCursorPosition();
- cellCursor.insertText(properties.at(i)->name());
- cell = table->cellAt(i + 1, 1);
- cell.setFormat(cellFormat);
- cellCursor = cell.firstCursorPosition();
- cellCursor.insertText(properties.at(i)->value().toString() + " " + properties.at(i)->unit());
- }
- cursor.movePosition(QTextCursor::End);
- cursor.insertBlock();
- //Print to PDF
- QPrinter printer(QPrinter::HighResolution);
- printer.setOutputFormat(QPrinter::PdfFormat);
- printer.setOutputFileName(filename);
- doc->print(&printer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement