This was very helpful to my Problem with Printing from QTableModel but I have encountered some hick ups
when i print a cell i use this
//i have initialized my painter like this
painter.scale(idealXScale, idealYScale);
painter.setClipping(true);
qDebug() << "hasClippings = "<< painter.hasClipping(); // this will always give me false
//i have initialized my painter like this
QPainter painter (printer);
painter.scale(idealXScale, idealYScale);
painter.setClipping(true);
qDebug() << "hasClippings = "<< painter.hasClipping(); // this will always give me false
To copy to clipboard, switch view to plain text mode
then i pass painter on to print a page
for (int r = info.startRow; r <= info.endRow; ++r)
{
for (int c = info.startCol; c <= info.endCol; ++c)
{
option.rect = visualRect(idx);
if (r % 2 == 0)
{
painter.fillRect(option.rect, brush);
}
itemDelegate()->paint(&painter, option, idx);
}
}
for (int r = info.startRow; r <= info.endRow; ++r)
{
for (int c = info.startCol; c <= info.endCol; ++c)
{
QModelIndex idx = model()->index(r,c);
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(idx);
if (r % 2 == 0)
{
QBrush brush(QColor(220, 220, 220), Qt::SolidPattern);
painter.fillRect(option.rect, brush);
}
itemDelegate()->paint(&painter, option, idx);
}
}
To copy to clipboard, switch view to plain text mode
now when the cell's content is clipped ( content not fully shown in the rect or maybe elided) then somehow the text will be printed but text is too big.
picture speaks a thousand words
Bookmarks