J-P,
You have NOTHING to apologize for!! You've been very helpful.
That's EXACTLY what needed to be done!!! I ran visualRect through qDebug() after every page and found that y() was incrementing by 1350. I also found out that after printing 45 rows, option.rect.x() was 1000 and not 0. So, I did painter->translate(0, -1350) after calling printer->newPage() and everything prints beautifully. I can't thank you enough for your help!! I was really appreciate it!
void PrintTableView
::printTable(QPrinter* printer,
QPainter* painter,
const QRect
& area
) {
const int rows = model()->rowCount();
const int columns = model()->columnCount();
double totalWidth = 0.0;
double totalPageHeight = 0.0;
double totalHeight = 0.0;
for (int c = 0; c < columns; ++c)
{
totalWidth += columnWidth(c);
}
for (int p = 0; p < 45; ++p)
{
totalPageHeight += rowHeight(p);
}
for (int r = 0; r<rows; ++r)
{
totalHeight += rowHeight(r);
}
const double xscale = area.width() / totalWidth;
const double yscale = area.height() / totalHeight;
const double pscale = area.height() / totalPageHeight;
painter->scale(xscale, pscale);
painter->translate(area.x() + xscale, area.y() + yscale);
bool ok;
int x=0;
for (int r = 0; r < rows; ++r) {
++x;
for (int c = 0; c < columns; ++c) {
option = viewOptions();
option.rect = visualRect(idx);
itemDelegate()->paint(painter, option, idx);
}
if (x == 45)
{
ok = printer->newPage();
x=0;
painter->translate(0, -1350);
}
}
}
void PrintTableView::printTable(QPrinter* printer, QPainter* painter, const QRect& area)
{
const int rows = model()->rowCount();
const int columns = model()->columnCount();
double totalWidth = 0.0;
double totalPageHeight = 0.0;
double totalHeight = 0.0;
for (int c = 0; c < columns; ++c)
{
totalWidth += columnWidth(c);
}
for (int p = 0; p < 45; ++p)
{
totalPageHeight += rowHeight(p);
}
for (int r = 0; r<rows; ++r)
{
totalHeight += rowHeight(r);
}
const double xscale = area.width() / totalWidth;
const double yscale = area.height() / totalHeight;
const double pscale = area.height() / totalPageHeight;
painter->scale(xscale, pscale);
painter->translate(area.x() + xscale, area.y() + yscale);
bool ok;
int x=0;
QStyleOptionViewItem option;
for (int r = 0; r < rows; ++r) {
++x;
for (int c = 0; c < columns; ++c) {
QModelIndex idx = model()->index(r,c);
option = viewOptions();
option.rect = visualRect(idx);
itemDelegate()->paint(painter, option, idx);
}
if (x == 45)
{
ok = printer->newPage();
x=0;
painter->translate(0, -1350);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks