rmagro
22nd September 2010, 16:57
Hi all,
I've just swiched from Qt 4.2.2 to Qt 4.4.3 anf the code I show below does not work anymore. It prints black lines .. any of you knows why it appens ??
Thank you in advance.
rmagro
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
QTableWidget *nuovaTableWidget = tableWidget;
QPrintDialog dlg(&printer, this);
if (dlg.exec() == QDialog::Accepted)
{
// calculate the total width/height table would need without scaling
const int rows = nuovaTableWidget->model()->rowCount();
const int cols = nuovaTableWidget->model()->columnCount();
double totalWidth = 0.0;
for (int c = 0; c < cols; ++c)
{
totalWidth += nuovaTableWidget->columnWidth(c);
}
double totalHeight = 0.0;
for (int r = 0; r < rows; ++r)
{
totalHeight += nuovaTableWidget->rowHeight(r);
}
double totalHeight1;
int numero_pagina = 1;
QPixmap pixmap(totalWidth, nuovaTableWidget->horizontalHeader()->height());
QPixmap pixmap1(totalWidth, totalHeight);
QPaintEvent event_1(QRect(0, 0, totalWidth, nuovaTableWidget->horizontalHeader()->height()));
QPaintEvent event_2(QRect(0, 0, totalWidth, totalHeight));
QPainter::setRedirected(nuovaTableWidget->horizontalHeader()->viewport(), &pixmap);
QApplication::sendEvent(nuovaTableWidget->horizontalHeader()->viewport(), &event_1);
QPainter::restoreRedirected(nuovaTableWidget->horizontalHeader()->viewport());
QPainter::setRedirected(nuovaTableWidget->viewport(), &pixmap1);
QApplication::sendEvent(nuovaTableWidget->viewport(), &event_2);
QPainter::restoreRedirected(nuovaTableWidget->viewport());
// print scaled pixmap
QPainter painter(&printer);
QDateTime dataDiOggi = QDateTime::currentDateTime();
QString dataDiOggiStringa = dataDiOggi.toString("dd.MM.yyyy hh:mm:ss");
painter.scale(4.5,4.5);
painter.drawPixmap(0, 100, totalWidth, nuovaTableWidget->horizontalHeader()->height(), pixmap);
painter.drawPixmap(0, 100+nuovaTableWidget->horizontalHeader()->height(), totalWidth, totalHeight, pixmap1);
}
I've just swiched from Qt 4.2.2 to Qt 4.4.3 anf the code I show below does not work anymore. It prints black lines .. any of you knows why it appens ??
Thank you in advance.
rmagro
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
QTableWidget *nuovaTableWidget = tableWidget;
QPrintDialog dlg(&printer, this);
if (dlg.exec() == QDialog::Accepted)
{
// calculate the total width/height table would need without scaling
const int rows = nuovaTableWidget->model()->rowCount();
const int cols = nuovaTableWidget->model()->columnCount();
double totalWidth = 0.0;
for (int c = 0; c < cols; ++c)
{
totalWidth += nuovaTableWidget->columnWidth(c);
}
double totalHeight = 0.0;
for (int r = 0; r < rows; ++r)
{
totalHeight += nuovaTableWidget->rowHeight(r);
}
double totalHeight1;
int numero_pagina = 1;
QPixmap pixmap(totalWidth, nuovaTableWidget->horizontalHeader()->height());
QPixmap pixmap1(totalWidth, totalHeight);
QPaintEvent event_1(QRect(0, 0, totalWidth, nuovaTableWidget->horizontalHeader()->height()));
QPaintEvent event_2(QRect(0, 0, totalWidth, totalHeight));
QPainter::setRedirected(nuovaTableWidget->horizontalHeader()->viewport(), &pixmap);
QApplication::sendEvent(nuovaTableWidget->horizontalHeader()->viewport(), &event_1);
QPainter::restoreRedirected(nuovaTableWidget->horizontalHeader()->viewport());
QPainter::setRedirected(nuovaTableWidget->viewport(), &pixmap1);
QApplication::sendEvent(nuovaTableWidget->viewport(), &event_2);
QPainter::restoreRedirected(nuovaTableWidget->viewport());
// print scaled pixmap
QPainter painter(&printer);
QDateTime dataDiOggi = QDateTime::currentDateTime();
QString dataDiOggiStringa = dataDiOggi.toString("dd.MM.yyyy hh:mm:ss");
painter.scale(4.5,4.5);
painter.drawPixmap(0, 100, totalWidth, nuovaTableWidget->horizontalHeader()->height(), pixmap);
painter.drawPixmap(0, 100+nuovaTableWidget->horizontalHeader()->height(), totalWidth, totalHeight, pixmap1);
}