2012-05-23 2 views
3

QTableView의 내용을 프린터로 인쇄하려고합니다. 나는 하단 스크립트를 구현하고 오류없이 성공적으로 실행됩니다. 그러나 모든 데이터는 printPreview에서 Unusual입니다. 당신이 나에게 말해주십시오 데 도움이 될 수있는 예를 들어이있는 경우 FOUNTAINpyqt 인쇄 미리보기 QTableView

def printTable(self,printer,painter,area): 
    model = self.model 
    myTableView = self.view 
    printer = painter 
    rows = model.rowCount(); 
    columns = model.columnCount(); 
    totalWidth = 0.0; 
    totalPageHeight = 0.0; 
    totalHeight = 0.0; 
    for c in range(columns): 
     totalWidth += myTableView.columnWidth(c) 

    for p in range(45): 
     totalPageHeight += myTableView.rowHeight(p); 

    for r in range(rows): 
     totalHeight += myTableView.rowHeight(r); 

    xscale = area.width()/totalWidth; 
    yscale = area.height()/totalHeight; 
    pscale = area.height()/totalPageHeight; 
    painter.scale(xscale, pscale); 
    painter.translate(area.x() + xscale, area.y() + yscale); 

    x=0 
    #QStyleOptionViewItem option; 

    for r in range(rows): 
     ++x 
     for c in range(columns): 
      idx = model.index(r,c); 
      option = myTableView.viewOptions(); 
      option.rect = myTableView.visualRect(idx); 
      if r % 2 == 0: 
       brush= QtGui.QBrush(QtGui.QColor(220, 220, 220), QtCore.Qt.SolidPattern); 
       painter.fillRect(option.rect, brush); 
      myTableView.itemDelegate().paint(painter, option, idx); 

     if (x == 45): 
      ok = printer.newPage(); 
      x=0; 
      painter.translate(0, -1350); 

####################### Now print Table ###################### 

printer = QtGui.QPrinter() 
painter = QtGui.QPainter() 
painter.begin(printer) 
self.printTable(printer,painter, printer.pageRect()) 

-이 내 문제에서 pic입니다. 고맙습니다.

+0

'++ x'는 파이썬에서 생각하는 것을하지 않습니다. 기본적으로 아무것도하지 않습니다. 그렇다면 최소한의 작업 예제 없이는 말하기가 어렵습니다. – mata

답변

1

C++을 사용하는 경우 전문가 용보고 도구를 사용할 것을 제안합니다. 사용할 수있는 옵션은 KDAB reporting toolNocisoft NC Report입니다. AFAIK PyQt에 대한 신뢰할 수있는보고 라이브러리가 없습니다 ...

+0

나는 일반적인 점에 동의하고, 화면 긁기와 위젯의 이미지는 이것에 관해 갈 수있는 좋은 방법이 아니다. 전에 QTextDocument 클래스를 사용했다. 생성 테이블은 자질구레 한 일이지만 출력을 HTML 또는 PDF로 내보내고 인쇄 할 수 있습니다. –