Now, I am able to print the horizontal header with the code below:
const int horizontal_height = horizontalHeader()->height();
const int vertical_width = verticalHeader()->width();
int width = horizontal_header_rect.size().width();
QWidget *view_port
= horizontalHeader
()->viewport
();
QPixmap horizontal_pixmap
(width, horizontal_height
);
QPaintEvent paint_horizontal_event
(horizontal_header_rect
);
dc->setRedirected(view_port, &horizontal_pixmap);
QApplication::sendEvent(view_port,
&paint_horizontal_event
);
dc->restoreRedirected(view_port);
dc
->drawPixmap
(printer
->pageRect
().
topLeft() + QPoint(vertical_width,
0), horizontal_pixmap, horizontal_header_rect
);
const int horizontal_height = horizontalHeader()->height();
const int vertical_width = verticalHeader()->width();
int width = horizontal_header_rect.size().width();
QWidget *view_port = horizontalHeader()->viewport();
QPixmap horizontal_pixmap(width, horizontal_height);
QPaintEvent paint_horizontal_event(horizontal_header_rect);
dc->setRedirected(view_port, &horizontal_pixmap);
QApplication::sendEvent(view_port, &paint_horizontal_event);
dc->restoreRedirected(view_port);
dc->drawPixmap(printer->pageRect().topLeft() + QPoint(vertical_width, 0), horizontal_pixmap, horizontal_header_rect);
To copy to clipboard, switch view to plain text mode
It could print nicely but, I still face a problem if the header is larger than the paper size. For example, I have a table with 33 columns. I could print nicely the header for the first 20 columns in first page, but fails to print for the remaining 13 columns in second page.
How could I modify the code to print the header nicely for the second page and all subsequent pages? Could any gurus out there helps?
Thanks.
Bookmarks