i have a Qt code writed in C++ . i want translate it to python code, but i have a problem in 4 code line:
all code is:
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");
but problem is here:
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);
}
please help me . thank you so much :)