PDA

View Full Version : QtextTable draw your own boarders



asweetroxxi
5th December 2012, 15:03
Hello,

I have a text atble i removed the boarders because i want to draw my own.

i want to look like this8478

any one know how to do this.
here is the code if need be

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::Borde rStyle_Inset);
tableFormat.setBorder(0);
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(4);

tableFormat.setWidth(QTextLength(QTextLength::Perc entageLength, 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();