我有一個Qt代碼在C++中編寫。我希望它翻譯成Python代碼,但是我已經在4號線的一個問題: 所有代碼:pyqt QTableView打印(4行C++代碼翻譯爲python)
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);
}
請幫助我。非常感謝你:)
有什麼實際問題?它不是在編譯?如果沒有,編譯器錯誤是什麼? – Brady
它正在編譯。我想翻譯c 2 py。問題到底在這裏: –
option.rect = self.visualRect(idx) –