asweetroxxi
27th November 2012, 21:43
i want to build an empty table in Qt which output into a pdf
here is what i got so far but im having issue. Is there something im missing, it's a bit messy i know i was doing some testing
QApplication a(argc, argv);
float j= 5;
QPrinter printer;
printer.setPageMargins(j,j,j,j,QPrinter::Inch);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPageSize(QPrinter::A4);
printer.printRange();
printer.setOutputFileName("C:\\qtpdf\\test.pdf");
QPainter painter;
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
return 1;
}
printer.newPage();
//creates writing format
QTextCharFormat NormalFormat;
//create pointer to current cursor location
QTextCursor cursor;
cursor.beginEditBlock();
QTextTableFormat tableFormat;
tableFormat.setBackground(QColor("#ffffff"));
tableFormat.setCellPadding(4);
tableFormat.setCellSpacing(3);
tableFormat.setBottomMargin(2);
QTextTable *tab = cursor.insertTable(30,30);
// tab->insertRows(20,1000);
// tab->insertColumns(20,10);
// QTextFrame *frame=cursor.currentFrame();
// QTextFrameFormat frameFormat;
// frameFormat.setBorder(0);
// frameFormat.setBorderStyle(QTextFrameFormat::Borde rStyle_Inset);
// frameFormat.setPageBreakPolicy(QTextFormat::PageBr eak_Auto);
// cursor.movePosition(QTextCursor::NextBlock);
// QTextCharFormat format_entete_tab;
// format_entete_tab.setFontPointSize(15);
// format_entete_tab.setFontWeight(QFont::Bold);
// QTextCharFormat format_cellule;
// format_cellule.setFontPointSize(11);
//// for(int i=0;i<100;i++)
//// {
//// //QTextTableCell titre = tab->cellAt(0,i);
//// tab->cellAt(0,i);
//// //QTextCursor cellCursor=titre.firstCursorPosition();
//// QTextCursor cellCursor;
//// cellCursor.insertText("hello");
//// }
// QTextTableCell cell;
// QTextCursor cellCursor;
// for(int row=1;row<500;row++)
// {
// for(int col=0;col<60;col++)
// {
// cell.firstPosition();
// //cellCursor=cell.firstCursorPosition();
// cellCursor.insertText("bye");
// }
// }
// cursor.endEditBlock();
painter.drawText(10, 10, "Test");
painter.drawText(100,100,"hello world");
// ret=renderToImage();
int x,y,z,h;
h= 950;
z= 950;
y= 450;
x= 10;
QRect rec(x,y,z,h);
QRect rec2(20,0,100,100);
if (h>j)
{
printer.newPage();
}
painter.drawRect(rec);
painter.drawRect(rec2);
// painter.drawRect(rec3);
printer.pageRect();
painter.drawText(rec,Qt::AlignLeft,"Left");
painter.drawText(rec,Qt::AlignCenter,"Center");
painter.drawText(rec,Qt::AlignRight,"Right");
painter.drawText(rec,Qt::AlignBottom,"low");
painter.drawText(rec2,Qt::AlignLeft,"No");
painter.drawText(rec2,Qt::AlignCenter,"Maybe");
painter.drawText(rec2,Qt::AlignRight,"Yes");
printer.newPage();
printer.fullPage();
if (! printer.newPage()) {
qWarning("failed in flushing page to disk, disk full?");
return 1;
}
painter.setBrush(Qt::SolidPattern);
int r,e;
r=10;
e=50;
QString hi = "aaaaaaa";
QPen pen(Qt::black, 2, Qt::SolidLine);
painter.setPen(pen);
QLineF line(10,10,685,10);
painter.drawLine(line);
painter.end();
MainWindow w;
w.show();
return a.exec();
here is what i got so far but im having issue. Is there something im missing, it's a bit messy i know i was doing some testing
QApplication a(argc, argv);
float j= 5;
QPrinter printer;
printer.setPageMargins(j,j,j,j,QPrinter::Inch);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPageSize(QPrinter::A4);
printer.printRange();
printer.setOutputFileName("C:\\qtpdf\\test.pdf");
QPainter painter;
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
return 1;
}
printer.newPage();
//creates writing format
QTextCharFormat NormalFormat;
//create pointer to current cursor location
QTextCursor cursor;
cursor.beginEditBlock();
QTextTableFormat tableFormat;
tableFormat.setBackground(QColor("#ffffff"));
tableFormat.setCellPadding(4);
tableFormat.setCellSpacing(3);
tableFormat.setBottomMargin(2);
QTextTable *tab = cursor.insertTable(30,30);
// tab->insertRows(20,1000);
// tab->insertColumns(20,10);
// QTextFrame *frame=cursor.currentFrame();
// QTextFrameFormat frameFormat;
// frameFormat.setBorder(0);
// frameFormat.setBorderStyle(QTextFrameFormat::Borde rStyle_Inset);
// frameFormat.setPageBreakPolicy(QTextFormat::PageBr eak_Auto);
// cursor.movePosition(QTextCursor::NextBlock);
// QTextCharFormat format_entete_tab;
// format_entete_tab.setFontPointSize(15);
// format_entete_tab.setFontWeight(QFont::Bold);
// QTextCharFormat format_cellule;
// format_cellule.setFontPointSize(11);
//// for(int i=0;i<100;i++)
//// {
//// //QTextTableCell titre = tab->cellAt(0,i);
//// tab->cellAt(0,i);
//// //QTextCursor cellCursor=titre.firstCursorPosition();
//// QTextCursor cellCursor;
//// cellCursor.insertText("hello");
//// }
// QTextTableCell cell;
// QTextCursor cellCursor;
// for(int row=1;row<500;row++)
// {
// for(int col=0;col<60;col++)
// {
// cell.firstPosition();
// //cellCursor=cell.firstCursorPosition();
// cellCursor.insertText("bye");
// }
// }
// cursor.endEditBlock();
painter.drawText(10, 10, "Test");
painter.drawText(100,100,"hello world");
// ret=renderToImage();
int x,y,z,h;
h= 950;
z= 950;
y= 450;
x= 10;
QRect rec(x,y,z,h);
QRect rec2(20,0,100,100);
if (h>j)
{
printer.newPage();
}
painter.drawRect(rec);
painter.drawRect(rec2);
// painter.drawRect(rec3);
printer.pageRect();
painter.drawText(rec,Qt::AlignLeft,"Left");
painter.drawText(rec,Qt::AlignCenter,"Center");
painter.drawText(rec,Qt::AlignRight,"Right");
painter.drawText(rec,Qt::AlignBottom,"low");
painter.drawText(rec2,Qt::AlignLeft,"No");
painter.drawText(rec2,Qt::AlignCenter,"Maybe");
painter.drawText(rec2,Qt::AlignRight,"Yes");
printer.newPage();
printer.fullPage();
if (! printer.newPage()) {
qWarning("failed in flushing page to disk, disk full?");
return 1;
}
painter.setBrush(Qt::SolidPattern);
int r,e;
r=10;
e=50;
QString hi = "aaaaaaa";
QPen pen(Qt::black, 2, Qt::SolidLine);
painter.setPen(pen);
QLineF line(10,10,685,10);
painter.drawLine(line);
painter.end();
MainWindow w;
w.show();
return a.exec();