printer.
setOrientation(QPrinter::Landscape);
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
()));
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
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
Bookmarks