PDA

View Full Version : Print entire QTableWidget



TonyInSoMD
7th January 2015, 11:39
I need to print an entire table with the table grid. Render only gives the visible part of the table. It will also have to cross multiple pages. It's a table with approximately 360 lines. As a separate issue I also need to be able to copy it to the clipboard but one thing at a time. Right now my focus is on printing the darn thing. ( I kept it clean). I wouldn't mind putting it in a double "for" loop and pull out the data as long as the printed copy is in a table format WITH the grid lines.

QPrinter printer(QPrinter::HighResolution);
QPrintDialog dlg_Print(&printer,this);
dlg_Print.exec();
QPainter painter;
painter.begin(&printer);
double xscale = printer.pageRect().width()/double(ui.m_tbl_AvailableHeaders->width());
double yscale = printer.pageRect().height()/double(ui.m_tbl_AvailableHeaders->height());
double scale = qMin(xscale,yscale);
painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
printer.paperRect().y() + printer.pageRect().height()/2);
painter.scale(scale,scale);
painter.translate(-width()/2,-height()/2);
ui.m_tbl_AvailableHeaders->render(&painter);

Thanks for any help anyone out there can give me.

Tony

anda_skoa
7th January 2015, 11:52
One idea would be to create a QTextDocument and add a table into it.
Either by using QTextTable or by creating a simple HTML table and let the document parse that.

Clipboard shouldn't be that hard either.
Most simple way is probably to create a CSV (comma separate value, optimall separator might differ depending on your data) text and put that up for consumption.
Alternatively, or even additonally (an application can offer clipboard content in more than one format), as an HTML table.

Cheers,
_

TonyInSoMD
7th January 2015, 13:02
Thanks a lot anda_skoa! I followed this link http://www.qtcentre.org/threads/53181-cell-division-problem-on-QTextDocument?highlight=QTextTable and it showed me how to create a table and add it to a document. I never would have found it without your help. Right now I'm going to set it up to print, when I get done with that I'll start working on the clipboard.

Tony