Qt使用QPrinter渲染QTablelView进行打印

时间:2015-03-11 18:34:10

标签: c++ qt printing qprinter

我正在尝试使用Qt打印发票。发票所需的其中一个功能是一个表格,我已决定使用QTabelWidget,因为我了解如何使用它们,但我收到一条错误说明"没有匹配的成员函数来调用'渲染'&#34 ;.如何解决此问题,甚至可以打印QTableView。我的代码在

之下
QPrinter Print;
Print.setPaperSize(QPrinter::A4);
Print.setOrientation(QPrinter::Landscape);
Print.setDuplex(QPrinter::DuplexAuto);
QTableWidget PrintTable;
PrintTable.setRowCount(ui->tableWidget_Invoice->rowCount());
PrintTable.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
PrintTable.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QTableWidgetItem *Product_CODE = new QTableWidgetItem;
QTableWidgetItem *Description = new QTableWidgetItem;
QTableWidgetItem *Unit_Price = new QTableWidgetItem;
QTableWidgetItem *Qty = new QTableWidgetItem;
QTableWidgetItem *Total_Price = new QTableWidgetItem;
for(int x =0; x<ui->tableWidget_Invoice->rowCount(); x++)
{
    Product_CODE->setText(ui->tableWidget_Invoice->item(x, 2)->text());
    Description->setText(ui->tableWidget_Invoice->item(x, 1)->text());
    Unit_Price->setText(ui->tableWidget_Invoice->item(x, 3)->text());
    Qty->setText(ui->tableWidget_Invoice->item(x, 0)->text());
    Total_Price->setText(ui->tableWidget_Invoice->item(x, 4)->text());
    PrintTable.setItem(x, 0, Product_CODE);
    PrintTable.setItem(x, 1, Description);
    PrintTable.setItem(x, 2, Unit_Price);
    PrintTable.setItem(x, 3, Qty);
    PrintTable.setItem(x, 4, Total_Price);
}
QHeaderView* header = PrintTable.horizontalHeader();
header->setSectionResizeMode(QHeaderView::Stretch);
PrintTable.render(Print);

0 个答案:

没有答案