dlg->setWindowTitle(tr("Print Table"));
if (dlg
->exec
() != QDialog::Accepted) return;
painter.begin(&printer);
double xscale = printer.pageRect().width();
double yscale = printer.pageRect().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.save();
const int ItemSize = 256;
float x = ItemSize /2;
for (int printRow = 0; printRow < rows; ++printRow) {
float y = ItemSize /2;
for (int column = 0; column < columns; ++column) {
option.
rect = QRect(int(x
),
int(y
), ItemSize, ItemSize
);
myTableView->itemDelegate()->paint(&painter, option, model->index(printRow, column, parent));
x = x + 256;
}
y = y + 256;
}
painter.restore();
painter.end();
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
dlg->setWindowTitle(tr("Print Table"));
if (dlg->exec() != QDialog::Accepted)
return;
QPainter painter;
painter.begin(&printer);
int rows = model->rowCount(QModelIndex());
int columns = model->columnCount(QModelIndex());
double xscale = printer.pageRect().width();
double yscale = printer.pageRect().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);
QModelIndex parent = QModelIndex();
painter.save();
QStyleOptionViewItem option;
const int ItemSize = 256;
float x = ItemSize /2;
for (int printRow = 0; printRow < rows; ++printRow) {
float y = ItemSize /2;
for (int column = 0; column < columns; ++column) {
option.rect = QRect(int(x), int(y), ItemSize, ItemSize);
myTableView->itemDelegate()->paint(&painter, option, model->index(printRow, column, parent));
x = x + 256;
}
y = y + 256;
}
painter.restore();
painter.end();
To copy to clipboard, switch view to plain text mode
Bookmarks