prabhudev
6th August 2012, 10:51
Hi i am using qtablewidget in my project..it has 10 columns & 5000 rows...i want to print the whole tablewidget... When i use the below code i get a empty pdf for 5000 rows...if i use it for less rows like 50 ,it prints only the visible area of the table widget...
How to solve this issue?
Is there any way do display a widget page wise , say 100 rows per page and take printout of 100 rows and print another 100 from 2nd page?
kindly help
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
QPrintDialog dlg(&printer, this);
if (dlg.exec() == QDialog::Accepted)
{
// calculate the total width/height table would need without scaling
const int rows = ui->Packet_Info->model()->rowCount();
const int cols = ui->Packet_Info->model()->columnCount();
double totalWidth = 0.0;
for (int c = 0; c < cols; ++c)
{
totalWidth += ui->Packet_Info->columnWidth(c);
}
double totalHeight = ui->Packet_Info->horizontalHeader()->height();
for (int r = 0; r < rows; ++r)
{
totalHeight += ui->Packet_Info->rowHeight(r);
}
// redirect table's painting on a pixmap
QPixmap pixmap(totalWidth, totalHeight );
QPainter::setRedirected(ui->Packet_Info->horizontalHeader()->viewport(), &pixmap);
QPainter::setRedirected(ui->Packet_Info->viewport(), &pixmap);
QPaintEvent event(QRect(0, 0, totalWidth, totalHeight ));
QApplication::sendEvent(ui->Packet_Info->horizontalHeader()->viewport(), &event);
QApplication::sendEvent(ui->Packet_Info->viewport(), &event);
QPainter::restoreRedirected(ui->Packet_Info->horizontalHeader()->viewport());
QPainter::restoreRedirected(ui->Packet_Info->viewport());
// print scaled pixmap
QPainter painter(&printer);
painter.scale(4,4);
//painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
painter.drawPixmap(printer.pageRect().topLeft(), pixmap, pixmap.rect());
}
How to solve this issue?
Is there any way do display a widget page wise , say 100 rows per page and take printout of 100 rows and print another 100 from 2nd page?
kindly help
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
QPrintDialog dlg(&printer, this);
if (dlg.exec() == QDialog::Accepted)
{
// calculate the total width/height table would need without scaling
const int rows = ui->Packet_Info->model()->rowCount();
const int cols = ui->Packet_Info->model()->columnCount();
double totalWidth = 0.0;
for (int c = 0; c < cols; ++c)
{
totalWidth += ui->Packet_Info->columnWidth(c);
}
double totalHeight = ui->Packet_Info->horizontalHeader()->height();
for (int r = 0; r < rows; ++r)
{
totalHeight += ui->Packet_Info->rowHeight(r);
}
// redirect table's painting on a pixmap
QPixmap pixmap(totalWidth, totalHeight );
QPainter::setRedirected(ui->Packet_Info->horizontalHeader()->viewport(), &pixmap);
QPainter::setRedirected(ui->Packet_Info->viewport(), &pixmap);
QPaintEvent event(QRect(0, 0, totalWidth, totalHeight ));
QApplication::sendEvent(ui->Packet_Info->horizontalHeader()->viewport(), &event);
QApplication::sendEvent(ui->Packet_Info->viewport(), &event);
QPainter::restoreRedirected(ui->Packet_Info->horizontalHeader()->viewport());
QPainter::restoreRedirected(ui->Packet_Info->viewport());
// print scaled pixmap
QPainter painter(&printer);
painter.scale(4,4);
//painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
painter.drawPixmap(printer.pageRect().topLeft(), pixmap, pixmap.rect());
}