我有一个用 C++ 编写的 Qt 代码。我想把它翻译成python代码,但我在4行有一个问题:所有代码都是:
void TableView::print(QPainter* painter, const QRect& area)
{
const int rows = model()->rowCount();
const int cols = 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);
}
// calculate proper scale factors
const double scaleX = area.width() / totalWidth;
const double scaleY = area.height() / totalHeight;
painter->scale(scaleX, scaleY);
// paint cells
for (int r = 0; r < rows; ++r)
{
for (int c = 0; c <; cols; ++c)
{
QModelIndex idx = model()->index(r, c);
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(idx);
itemDelegate()->paint(painter, option, idx);
}
}
}
// printer usage
QPainter painter(&printer);
tableView->print(&painter, printer.pageRect());
// test on pixmap
QPixmap pixmap(320, 240);
QPainter painter(&pixmap);
tableView->print(&painter, pixmap.rect());
pixmap.save("table.png", "PNG");
但问题在这里:
for (int c = 0; c < cols; ++c)
{
QModelIndex idx = model()->index(r, c);
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(idx);
itemDelegate()->paint(painter, option, idx);
}
请帮我 。太感谢了 :)