// editor->setDocumentMargin(25);
//creates writing format
NormalFormat.
setFont(QFont("Helvetica",
20,
QFont::Bold));
block.setAlignment(Qt::AlignBottom);
//create pointer to current cursor location
cursor.beginEditBlock();
cursor.setBlockFormat(block);
cursor.insertBlock();
cursor.insertBlock();
cursor.insertBlock();
cursor.insertText(" ",NormalFormat);
cursor.insertText("Escort Data Logger Report",NormalFormat);
cursor.insertBlock();
cursor.insertBlock();
cursor.insertBlock();
tableFormat.
setBackground(QColor("#ffffff"));
tableFormat.setBorder(0);
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(4);
QTextTable *tab
=cursor.
insertTable(tabW
->rowCount
()+1,tabW
->columnCount
(),tableFormat
);
cursor.insertFrame(frameFormat);
cursor.setPosition(frame->lastPosition());
frame->setFrameFormat(frameFormat);
format_entete_tab.setFontPointSize(15);
format_entete_tab.
setFontWeight(QFont::Bold);
format_cellule.setFontPointSize(12);
for(int i=0;i<tabW->columnCount();i++)
{
QTextTableCell titre
= tab
->cellAt
(0,i
);
// change 0 it moves the title cellCursor.insertText(tabW->horizontalHeaderItem(i)->text(),format_entete_tab);
}
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();
QTextDocument *editor = new QTextDocument;
// editor->setDocumentMargin(25);
//creates writing format
QTextCharFormat NormalFormat;
NormalFormat.setFont(QFont("Helvetica",20,QFont::Bold));
QTextBlockFormat block;
block.setAlignment(Qt::AlignBottom);
//create pointer to current cursor location
QTextCursor cursor (editor);
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::Start);
cursor.setBlockFormat(block);
cursor.insertBlock();
cursor.insertBlock();
cursor.insertBlock();
cursor.insertText(" ",NormalFormat);
cursor.insertText("Escort Data Logger Report",NormalFormat);
cursor.insertBlock();
cursor.insertBlock();
cursor.insertBlock();
QTextTableFormat tableFormat;
tableFormat.setBackground(QColor("#ffffff"));
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Inset);
tableFormat.setBorder(0);
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(4);
tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
QTextTable *tab=cursor.insertTable(tabW->rowCount()+1,tabW->columnCount(),tableFormat);
QTextFrame *frame=cursor.currentFrame();
QTextFrameFormat frameFormat=frame->frameFormat();
cursor.insertFrame(frameFormat);
cursor.setPosition(frame->lastPosition());
frame->setFrameFormat(frameFormat);
QTextCharFormat format_entete_tab;
format_entete_tab.setFontPointSize(15);
format_entete_tab.setFontWeight(QFont::Bold);
QTextCharFormat format_cellule;
format_cellule.setFontPointSize(12);
for(int i=0;i<tabW->columnCount();i++)
{
QTextTableCell titre = tab->cellAt(0,i);// change 0 it moves the title
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();
To copy to clipboard, switch view to plain text mode
Bookmarks