teikchuan
27th March 2009, 05:35
Hi,
I would like to print a table which contains text only. I search through the forum and found this piece of code
QPainter painter(printer);
const QRect area = printer->pageRect();
const int rows = m_data_model.rowCount();
const int cols = m_data_model.columnCount();
// calculate the total width/height table would need without scaling
double totalWidth = 0.0;
for (int c = 0; c < cols; ++c)
{
totalWidth += columnWidth(c);
}
double totalHeight = 0.0;
for (int r = 0; r < rows; ++r)
{
totalHeight += rowHeight(r);
}
// paint cells
for (int r = 0; r < rows; ++r)
{
for (int c = 0; c < cols; ++c)
{
QModelIndex idx = m_data_model.index(r, c);
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(idx);
itemDelegate()->paint(&painter, option, idx);
}
}
However, the code does not print the table's vertical and horizontal headers, as well as the grid lines. How can I print a table, with both the headers and the grid lines?
I am using Qt4.4.
Thanks.
I would like to print a table which contains text only. I search through the forum and found this piece of code
QPainter painter(printer);
const QRect area = printer->pageRect();
const int rows = m_data_model.rowCount();
const int cols = m_data_model.columnCount();
// calculate the total width/height table would need without scaling
double totalWidth = 0.0;
for (int c = 0; c < cols; ++c)
{
totalWidth += columnWidth(c);
}
double totalHeight = 0.0;
for (int r = 0; r < rows; ++r)
{
totalHeight += rowHeight(r);
}
// paint cells
for (int r = 0; r < rows; ++r)
{
for (int c = 0; c < cols; ++c)
{
QModelIndex idx = m_data_model.index(r, c);
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(idx);
itemDelegate()->paint(&painter, option, idx);
}
}
However, the code does not print the table's vertical and horizontal headers, as well as the grid lines. How can I print a table, with both the headers and the grid lines?
I am using Qt4.4.
Thanks.